0

I try to learn node.js, and I want to use express framework for it, but when i copy and paste hello world example from expressjs.com page, it shows error:

/home/tomek/dev/node/express_server.js:1
uire, module, __filename, __dirname) { var app = require('express').createServ
                                                                    ^
TypeError: undefined is not a function
    at Object.<anonymous> (/home/tomek/dev/node/express_server.js:1:92)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Function.Module.runMain (module.js:490:10)
    at startup (node.js:124:16)
    at node.js:807:3

I've installed express through npm and it looks ok. Its in node_modules folder in app's root directory.

0

1 Answer 1

1

createServer is depracated. I dont know if server will not run, or just ping You with a warning, but we cant tell anything, as You didnt paste Your code.

If You use express 4, You can create server instance:

var express = require('express'),
    app = express();

instead of createServer.

here is official guide for express: http://expressjs.com/guide.html

You can also check for ie this link: http://scotch.io/tutorials/javascript/build-a-restful-api-using-node-and-express-4 guide for whole restful api tutorial as good example of creating server with some routing in new express (lot of tutorials are outdated).

Sign up to request clarification or add additional context in comments.

2 Comments

It worked but when I run the app I get TypeError: Cannot read property 'handle' of undefined
Someone actually solved it for me here: link

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.