npm express “hello world” middleware error

后端 未结 4 1166

node --version v0.10.26

npm --version 1.4.3

I followed this: http://expressjs.com/guide.html

which has this code

    var express = re         


        
相关标签:
4条回答
  • 2021-01-04 15:31

    Most middleware (like logger) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware

    express.logger('dev') is removed from express module.

    use logger like morgan.

    var morgan = require("morgan");
    app.use(morgan('combined'));
    

    for more details on morgan checkout the below link morgan

    0 讨论(0)
  • 2021-01-04 15:37

    The first line tells it all:

    Error: Most middleware (like logger) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

    Looking at https://github.com/senchalabs/connect#middleware we can see that express.logger has been replaced with morgan.

    var logger = require('morgan');
    app.use(logger); //replaces your app.use(express.logger());
    

    Remember to npm install morgan and/or add it to your package.json

    0 讨论(0)
  • 2021-01-04 15:42

    I faced the same problem. I ran the below from the directory where my node js file was

    npm install --save morgan
    

    Using above command adds the dependency to your package.json.

    Once package added, logger can now be used as

    logger = require('morgan');
    app.use(logger('dev'));
    
    0 讨论(0)
  • 2021-01-04 15:54

    You need a previous version:

    npm install express@3.0.0
    
    0 讨论(0)
提交回复
热议问题