I'm a node newbie so forgive me if this is something simple.
I am trying to run a callback once a function has finished. No matter which way around I try it, the callback keeps executing first.
My module import_data.js
module.exports.download = function(url, path, supplier, callback) {
//SF add dates to logging
console.log('Import for '+supplier+' started');
request({uri: url})
.pipe(fs.createWriteStream(path))
.on('close', function() {
console.log('Import complete');
},function(err, data){
callback;
});
};
import_js is called into common
'use strict';
//var db = require('../config/sequelize').sequelize;
var common = require('./common/index.js'),
async = require('async');
common.importData(
'www.url.com',
'/tmp/target.csv',
'Target Compenents',
console.log('callback')
);
I would expect the console.log('calback') to be the last thing logged.
Any help greatly appreciated.
You have to add a function as your callback, console.log it's only method it isn't a function which you can use as a callback.
So and to fix it you can wrap your console.log into function like below:
common.importData(
'www.url.com',
'/tmp/target.csv',
'Target Compenents',
function(){console.log('callback')}
);
i hope it will help you thanks!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments