Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Node.js - Callback is not a function

Lock:

I am trying to retrieve a var Hash to use it in another module. but I have a problem with Callback. I have the error "callback is not a function". I use callback because my variable hash is undefined, so i guess it's a problem of asynchronous.

Could you help me plz :)

hash.js


var fs = require('fs');
var crypto = require('crypto');
var algorithm = 'sha256';

var hash = function(filename, callback){
var shasum = crypto.createHash(algorithm);
var s = fs.ReadStream(filename);

s.on('data', function(data) {
shasum.update(data)
})
s.on('end', function() {
var hash = shasum.digest('hex')
callback(hash);
})
}

exports.hash = hash;

app.js


app.post('/upload', upload.single('userfile'), function(req, res){

res.cookie('filename', req.file.originalname);
res.cookie('filesize', req.file.size);
var filename = __dirname +'/'+ req.file.path;
console.log(hash.hash(filename))

//res.cookie('hash', hash.hash(filename));
res.redirect('/hash')
})



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Node.js - Callback is not a function

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×