I have been trying to learn node.js. I am trying to create a simple node.js web api and a html-javascript front end to login using Facebook auth and store Facebook id in Mongodb.
I was able to do it by following tutorials available online.
Now I want to segregate the code into multiple files but when I try to create a route "user" and expose functions via exports. I am getting the following error.
module.exports.userLogin = function(req,res){
^ SyntaxError: Unexpected token .
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (C:\Users\Saumya\Desktop\vhsharedraft\web.js:2:6)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
EDIT#1
module.exports.userLogin = function(req,res){
graph.setAccessToken(req.session.fb.access_token);
graph.get("/me", function(err, data) {
if(err){
console.log('Error obtaining data.');
return;
}
console.log(data);
}
}
EDIT # 2
var mongo = require('mongodb'),
graph = require('fbgraph');
exports.userLogin = function(req,res){
graph.setAccessToken(req.session.fb.access_token);
graph.get("/me", function(err, data) {
if(err){
console.log('Error obtaining data.');
return;
}
console.log(data);
}
}
This is all I have in user route.
Actually, I was making a real silly mistake, I left a comma in front of graph = require('fbgraph')
instead of semi colon.
After fixing this syntax error, I am getting this error.
}
^
SyntaxError: Unexpected token }
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (C:\Users\Saumya\Desktop\vhsharedraft\web.js:2:6)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
exports.funcName = function() { }
, so I'd start there. If I could see the rest of the code around where it's failing I could probably be more helpful. – Purdyexports.userLogin =
instead ofmodule.exports.userLogin
. Secondly is there any other code in the file? 3rd, how are you getting that error, what command are you using? – Purdy