This is my first javascript file which is called search.js which is used to query through twitter posts.
var Twit = require('twit');
var config = require('./config')
var T = new Twit(config);
var params = {
q: '#stackOverflow',
count: 1
}
var response = null;
T.get('search/tweets', params, searchedData);
function searchedData(err, data, response) {
response = data
console.log(response) //prints the post
return response;
}
The twitter posts are stored in the 'response' variable returned in the last function. When I print the response variable, it properly prints the post. I need to access that variable in my index.js which runs the server.
Here is my index.js file:
const mySearch = require('./search.js');
const express = require('express');
const app = express();
app.get('/', function(req, res) {
res.send('Hello World');
})
app.listen(3000, function(){
console.log("Server started on port 3000...");
console.log(mySearch.response)//prints 'undefined'
})
Can anyone please help me? I tried looking online but I still can't put the pieces together.
Thanks!