node.js - Cant find methods in Express -


i have node js code this:

var express = require('express')   , app = express.createserver();  app.use(express.bodyparser());  app.post('/', function(request, response){   console.log(request.body);      // json   response.send(request.body);    // echo result });  app.listen(3000); 

when run error this:

  , app = express.createserver();                   ^ typeerror: object function createapplication() {   var app = function(req, res, next) {     app.handle(req, res, next);   };    mixin(app, proto);   mixin(app, eventemitter.prototype);    app.request = { __proto__: req, app: app };   app.response = { __proto__: res, app: app };   app.init();   return app; } has no method 'createserver'     @ object.<anonymous> (/users/anto_belgin/programs/node/appleconnect.js:2:19)     @ module._compile (module.js:456:26)     @ object.module._extensions..js (module.js:474:10)     @ module.load (module.js:356:32)     @ function.module._load (module.js:312:12)     @ function.module.runmain (module.js:497:10)     @ startup (node.js:119:16)     @ node.js:902:3 

i have installed express using:

npm install express 

is there need working?

in express 4 app, i'm doing this:

var express = require('express');  var app = express();  var server = app.listen(8081, function() {}); 

since express changed bit v3 v4, make sure you're looking @ instructions version running.

i think createserver() on http module, whereas express runs @ higher level on top of if you're starting server using express module, differently.

from express documentation, app.listen() convenience method replaces this:

app.listen = function(){   var server = http.createserver(this);   return server.listen.apply(server, arguments); }; 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -