简体   繁体   中英

How to Read npm-debug.log (Troubleshoot Node.JS App)

I am trying to follow some tutorials on authentication using Passport in Node.JS apps and have realized that I am unsure on how to troubleshoot NodeJS apps using npm-debug.log as I am generally on the AngularJS side. In particular, I have the following trouble. Could someone tell me what could be the issue? I can post additional relevant code, if needed.

npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@3.5.0
3 info using node@v5.1.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle passport-local@0.0.0~prestart: passport-local@0.0.0
6 silly lifecycle passport-local@0.0.0~prestart: no script for prestart, continuing
7 info lifecycle passport-local@0.0.0~start: passport-local@0.0.0
8 verbose lifecycle passport-local@0.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle passport-local@0.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/selfishman/www/sites/Playground/passport-local/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin
10 verbose lifecycle passport-local@0.0.0~start: CWD: /Users/selfishman/www/sites/Playground/passport-local
11 silly lifecycle passport-local@0.0.0~start: Args: [ '-c', 'node ./bin/www' ]
12 silly lifecycle passport-local@0.0.0~start: Returned: code: 1  signal: null
13 info lifecycle passport-local@0.0.0~start: Failed to exec start script
14 verbose stack Error: passport-local@0.0.0 start: `node ./bin/www`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack     at emitTwo (events.js:87:13)
14 verbose stack     at EventEmitter.emit (events.js:172:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
14 verbose stack     at emitTwo (events.js:87:13)
14 verbose stack     at ChildProcess.emit (events.js:172:7)
14 verbose stack     at maybeClose (internal/child_process.js:818:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
15 verbose pkgid passport-local@0.0.0
16 verbose cwd /Users/selfishman/www/sites/Playground/passport-local
17 error Darwin 14.5.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 error node v5.1.0
20 error npm  v3.5.0
21 error code ELIFECYCLE
22 error passport-local@0.0.0 start: `node ./bin/www`
22 error Exit status 1
23 error Failed at the passport-local@0.0.0 start script 'node ./bin/www'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the passport-local package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     node ./bin/www
23 error You can get their info via:
23 error     npm owner ls passport-local
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use(require('express-session')({
    secret : 'keyboard cat',
    resave : false,
    saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());

app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);

//passport config
var Account = require('./models/account');
passport.use(new LocalStrategy(Account.authenticate()));
passport.serializeUser(Account.serializeUser());
passport.desirializeUser(Account.deserializeUser());

//mongoose
mongoose.connect('mongodb://localhost/passport_local_mongoose_express4');

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});


module.exports = app;

package.json

{
  "name": "passport-local",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "^1.13.2",
    "chai": "~1.8.1",
    "cookie-parser": "^1.3.5",
    "debug": "^2.1.1",
    "express": "^4.13.1",
    "express-session": "^1.10.1",
    "jade": "^1.11.0",
    "mocha": "~1.14.0",
    "mongodb": "^2.1.18",
    "mongoose": "^3.8.22",
    "morgan": "^1.6.1",
    "passport": "^0.2.1",
    "passport-local": "^1.0.0",
    "passport-local-mongoose": "^1.0.0",
    "serve-favicon": "^2.2.0",
    "should": "~2.1.0"
  }
}

Short answer: This problem has nothing to do with npm. Your application has a bug that throws an exception. If you start your application as

node ./bin/www

then you will see the exception with stack trace on the console, without any interference of npm.

Longer answer: Let's read the files to come to the above conclusion:

npm-debug.log --- line 1:

verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]

This tells us that you just called npm start . You probably knew that already.

package.json scripts:

"start": "node ./bin/www"

This tells you that npm did nothing but calling node ./bin/www

npm-debug.log line 14:

14 verbose stack Error: passport-local@0.0.0 start: `node ./bin/www`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack     at emitTwo (events.js:87:13)
14 verbose stack     at EventEmitter.emit (events.js:172:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
14 verbose stack     at emitTwo (events.js:87:13)
14 verbose stack     at ChildProcess.emit (events.js:172:7)
14 verbose stack     at maybeClose (internal/child_process.js:818:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

This is part of your stack trace. You will get a similar output when you call your application without npm .

I don't have enough information to debug your program from here --- but I hope it helps you to know that this is just a normal exception thrown somewhere in your app and nothing related to npm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM