Trying to make a login app with nodejs express. However after I run it. it shows TypeError: express.Router is not a function. My express is the latest version4.13.4. Can anyone help me?Here is the code.
var User = require('../modules/user');
var config = require('../../config');
var secretKey = config.secretKey;
module.exports = function(app,express){
var api = express.Router;
api.post('/signup', function(req,res){
var user = new User({
name: req.body.name,
username: req.body.username,
password: req.body.password
});
user.save(function(err){
if(err){
res.send(err);
return;
}
res.json({ message: 'user has been created'});
})
});
return api;
};
It should be var api = express.Router();
I can't see the require to include the express library.
var express = require('express');
var app = express();
Also remember to make
$ npm install express --save
To install it.
Here is the reference
http://expressjs.com/en/4x/api.html
http://expressjs.com/en/starter/installing.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With