Hi I am trying to create a nodejs server running on port 3000. I have already installed express (npm install express).
I am getting the following error message
TypeError: express.createServer is not a function
at Object.<anonymous> (C:\nodejs\index.js:1:111)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
The code I am using is
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res) {
res.send('I am listening');
});
app.listen(3000);
Use express() instead of createServer()
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('I am listening');
});
app.listen(3000);
module.exports = function(app){
var apiRoutes = require('./routes/apiRoutes');
app.get('/view', apiRoutes.view);
app.get('/add',apiRoutes.add);
app.post('/register',apiRoutes.register);
app.get('/user/:id',apiRoutes.Edit);
app.post('/update/:id',apiRoutes.Update);
//app.delete('/user/delete/:id',apiRoutes.delete);
app.post('/login',apiRoutes.login);
app.get('/homepage',apiRoutes.homepage);
};
there are the error in api.js
1) get should return status 401 unauthorized due to lack of auth token on /users GET: Uncaught TypeError: app.get is not a function at Server.module.exports (api.js:4:9) at parserOnIncoming (_http_server.js:619:12) at HTTPParser.parserOnHeadersComplete (_http_common.js:112:17)