我正在测试护照,为了更好地理解,我试图将护照中的示例实施到我的应用程序中。 但是因为我已经这样做了我无法启动nodemon app.js(节点app.js正在运行)。控制台一直告诉我:
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\User\AppData\Roaming\npm\node_modules\nodemon\nodemon.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
所以这是我的包JSON和app.js:
的package.json
{
"name": "myApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "*",
"jade": "*",
"less": "*",
"connect": "*",
"connect-flash": "*",
"lingua": "*",
"mysql": "*",
"now": "*",
"passport": "*",
"passport-local": "*"
},
"engines": {
"node": ">= 0.10.x",
"npm": "*"
}
}
app.js
/**
* Module dependencies.
*/
var express = require('express'),
flash = require('connect-flash'),
routes = require('./routes'),
user = require('./routes/user'),
http = require('http'),
path = require('path'),
lingua = require('lingua'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy;
// Passport Test Setup
var users = [
{ id: 1, username: 'bob', password: 'secret', email: 'bob@example.com' }
, { id: 2, username: 'joe', password: 'birthday', email: 'joe@example.com' }
];
function findById(id, fn) {
var idx = id - 1;
if (users[idx]) {
fn(null, users[idx]);
} else {
fn(new Error('User ' + id + ' does not exist'));
}
}
function findByUsername(username, fn) {
for (var i = 0, len = users.length; i < len; i++) {
var user = users[i];
if (user.username === username) {
return fn(null, user);
}
}
return fn(null, null);
}
// Passport session setup.
// To support persistent login sessions, Passport needs to be able to
// serialize users into and deserialize users out of the session. Typically,
// this will be as simple as storing the user ID when serializing, and finding
// the user by ID when deserializing.
passport.serializeUser(function (user, done) {
done (null, id);
});
passport.deserializeUser(function (id, done) {
done (null, id);
});
// Use the LocalStrategy within Passport.
// Strategies in passport require a `verify` function, which accept
// credentials (in this case, a username and password), and invoke a callback
// with a user object. In the real world, this would query a database;
// however, in this example we are using a baked-in set of users.
passport.use(new LocalStrategy(
function(username, password, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// Find the user by username. If there is no user with the given
// username, or the password is not correct, set the user to `false` to
// indicate failure and set a flash message. Otherwise, return the
// authenticated `user`.
findByUsername(username, function(err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false, { message: 'Unknown user ' + username }); }
if (user.password != password) { return done(null, false, { message: 'Invalid password' }); }
return done(null, user);
})
});
}
));
var app = express();
// configure Express
app.configure(function() {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(lingua(app, {
defaultLocale: 'en-US',
path: __dirname + '/languages',
storageKey: 'lang'
}));
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({ secret: 'keyboard cat'}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
// app.get
app.get('/', function(req, res) {
res.render('index', { user: req.user });
});
app.get('/account', ensureAuthenticated, function(req, res){
res.render('account', { user: req.user });
});
app.get('/login', function(req, res) {
res.render('login', { user: req.user, message: req.flash('error')});
});
// Simple route middleware to ensure user is authenticated.
// Use this route middleware on any resource that needs to be protected. If
// the request is authenticated (typically via a persistent login session),
// the request will proceed. Otherwise, the user will be redirected to the
// login page.
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
res.redirect('/login')
}
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
有没有人知道可能出了什么问题?
问候