Nodejs connect using built-in modules & # 8594; method not found

when i call this node.js file

var connect = require('connect'); var app = connect(); app.use(connect.static('public')); app.listen(3000); 

I get right away

 app.use(connect.static('public')); ^ TypeError: Object function createServer() { function app(req, res, next){ app.handle(req, res, next); } merge(app, proto); merge(app, EventEmitter.prototype); app.route = '/'; app.stack = []; return app; } has no method 'static' 

Using Connect 3.0.1, are there any changes in the integrated modules? If so, how does it work?

+7
connect
source share
2 answers

big changes related to connection 3: middleware modules are no longer included. Find them at github.com/expressjs . "static" is now "serves-static". It must be installed separately with:

npm install serve-static

The code above should look like this:

 var connect = require('connect'); var serveStatic = require('serve-static'); var app = connect(); app.use(serveStatic('public')); app.listen(3000); 
+13
source share

I had to install connect and serve-static

 npm install connect 

then enter:

 npm install serve-static 

In the code below you will get a good message that your server is connected to port 3000.

 var connect = require('connect'); var serveStatic = require('serve-static'); var app = connect(); var port = 3000; app.use(serveStatic(__dirname)); app.listen(port); console.log('You are connected at port '+port); 
+1
source share

All Articles