3

While trying to execute server.js program I am getting the following error:

var app = express();
Type error: object is not a function 
   at object.<anonymous>

even tried re installing and changing the version of express to

npm install
npm uninstall express
npm install [email protected]

but it resulted in new error

fqdn = ~req.url.indexof(' ://')

I use windows and i am working on node.js version 0.8.4.

2 Answers 2

5

If you're using Express < 3.0, the return value of require('express'); is not a function; you'll need to create a server the old way.

Express 2.x

var express = require('express');
var server = express.createServer();

Express 3.x

var http = require('http');
var express = require('express');
var app = express();
var server = http.createServer(app);
Sign up to request clarification or add additional context in comments.

Comments

0

What does

> require('express').version;
'3.0.0rc2'

return?

As you can see it does return 3.0.0rc2? Does yours really return 2.5.9. if it does you use like Brandon said 2.x section. If it returns 3.x you use his 3.x section.

3 Comments

require is not recognized as an internal or external command says the reply. and since i have passed npm install [email protected] so version 2.5.9 must have got installed only.
Alfred was intending you to do that from within node's REPL, not directly from the command line.
Yup from within the REPL, because it might be possible you think you have some version while in fact you have another version...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.