Question

I am following a tutorial in which i am setting up a node.js server and mongoDB database. I am at a point where i need to start npm, but this is the error it returns

C:\Users\Jay\IdeaProjects\nodetest1>npm start

> application-name@0.0.1 start C:\Users\Jay\IdeaProjects\nodetest1
> node ./bin/www


    module.js:340
        throw err;
              ^
    Error: Cannot find module 'bodyParser'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (C:\Users\Jay\IdeaProjects\nodetest1\app.js:6:18)
        at Module._compile (module.js:456:26)
        at Object.Module._extensions..js (module.js:474:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Module.require (module.js:364:17)

npm ERR! application-name@0.0.1 start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the application-name@0.0.1 start script.
npm ERR! This is most likely a problem with the application-name package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get their info via:
npm ERR!     npm owner ls application-name
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\Users\Jay\IdeaProjects\nodetest1
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\Jay\IdeaProjects\nodetest1\npm-debug.log
npm ERR! not ok code 0

I have followed the tutorial thoroughly and am quite new to node/mongo so if anyone knows how to help, i'd appreciate it.

Here is my app.js code

var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('bodyParser');

//Database
var mongo = require('mongoskin');
var db = mongo.db("mongodb://localhost:27017/nodetest1", {native_parser:true});

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');

app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

//Make our db accessible to our router
app.use(function(req,res,next){
    req.db = db;
    next();
});

app.use('/', routes);
app.use('/users', users);

///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: {}
        });
    });
}

//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;
Was it helpful?

Solution

Looks like you need to install the node modules. npm install -d should install all the dependencies.

Your bodyParser is wrong as well. It should be:

var bodyParser = require('body-parser')

see: body parser API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top