Reputation: 687
I am running a small twitter stream with npm that is printing tweets to my console. I would like to write them to disk but my server is not doing this. Here is my routes.js file:
var Twit = require('twit'), // wrapper on top of twitter api
dotenv = require('dotenv'), // used for keys -> get from .env
fs = require('fs');
module.exports = function(app) {
dotenv.load();
var T = new Twit({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_SECRET_KEY,
access_token: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_KEY
});
var middleEast = ['29.4' , '33.7' , '37.7' , '46.1' ]
var stream = T.stream('statuses/filter', {track: '#ISIS', language: 'en'})
stream.on('tweet', function(tweet) {
if (tweet.geo!=null){
console.log(tweet.geo.coordinates)
}
console.log(tweet.text)
fs.appendFile("./ISIStweets.json", tweet.text)
})
This writes nothing to file. However, identical code in the same folder, shown below, successfully writes to file. What gives?
var fs = require('fs');
fs.appendFile("./ISIStweets.json", "Hello there!\n")
Upvotes: 1
Views: 261
Reputation: 3853
There are a couple of things that could've happened here:
Does the console log anything at all? It could be that your tweet stream actually isn't streaming anything.
Do you have permission to write to the ISIStweets.json
file? If the file already exists, it might be owned by someone other than the user that's running node. If the file doesn't exist, check that you have permission to write in this directory.
Upvotes: 1