So I'm following This Tutorial here to get a personal/learning node.js project off the ground that I would like to work on and store in GitHub and eventually put onto a live server or cloud hosting. It's using node.js, express, monk, mongoDB for a website setup. However I have a persistent error that I haven't found an answer to when I run 'npm start'.
Here is my command window output when I try to run 'npm start' inside my node express project.
I know that: Error: Cannot find module 'C:\Users\username\Desktop\bin\www' is not where my bin\www is located (it's inside the nodetest1 project).
C:\Users\username\Documents\GitHub\TEDResources\node.js\nodetest1 <-- correct path
So, why is npm looking at that incorrect spot and how do I update it to correctly look at my project folder? I've searched my system and can't find module.js anywhere. (using windows 7 x64) I've also tried nuking node.js and express and started from scratch without luck.
//console error output
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\username\Documents\GitHub\TEDResources\node.js\nodetest1>npm start
> [email protected] start C:\Users\username\Documents\GitHub\TEDResources\node.j
s\nodetest1
> node ./bin/www
module.js:340
throw err;
^
Error: Cannot find module 'C:\Users\username\Desktop\bin\www'
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:906:3
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is most likely a problem with the nodetest1 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 nodetest1
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\Users\username\Documents\GitHub\TEDResources\node.js\nodetest1
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\username\Documents\GitHub\TEDResources\node.js\nodetest1
\npm-debug.log
npm ERR! not ok code 0
//npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose run-script [ 'prestart', 'start', 'poststart' ]
6 info prestart [email protected]
7 info start [email protected]
8 verbose unsafe-perm in lifecycle true
9 info [email protected] Failed to exec start script
10 error [email protected] start: `node ./bin/www`
10 error Exit status 8
11 error Failed at the [email protected] start script.
11 error This is most likely a problem with the nodetest1 package,
11 error not with npm itself.
11 error Tell the author that this fails on your system:
11 error node ./bin/www
11 error You can get their info via:
11 error npm owner ls nodetest1
11 error There is likely additional logging output above.
12 error System Windows_NT 6.1.7601
13 error command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
14 error cwd C:\Users\kellington\Documents\GitHub\TEDResources\node.js\nodetest1
15 error node -v v0.10.32
16 error npm -v 1.4.28
17 error code ELIFECYCLE
18 verbose exit [ 1, true ]
//package.json
{
"name": "nodetest1",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.9.0",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3",
"debug": "~2.0.0",
"jade": "~1.6.0",
"mongodb": "*",
"monk": "*"
}
}
//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 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(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
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: 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;
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
//dir result
> [email protected] start C:\Users\username\Documents\GitHub\TEDResources\node.j
s\nodetest1
> dir
Volume in drive C is OS
Volume Serial Number is F87D-8771
Directory of C:\Users\username\Desktop
10/23/2014 11:13 AM <DIR> .
10/23/2014 11:13 AM <DIR> ..
10/13/2014 09:14 AM 146,016 7f6bd778-1c67-43fd-9865-372789ed7592_Loca
lIISWebsite.zip
10/07/2014 03:39 PM 1,086 Blue Eye Macro.lnk
08/28/2014 12:07 PM 1,197 DesignEphiphany.txt
10/22/2014 08:03 AM 2,163 Git Shell.lnk
04/17/2014 10:51 AM 308 GitHub.appref-ms
10/21/2014 10:54 AM <DIR> LocalIISWebsite
10/23/2014 11:11 AM <DIR> node.js
10/14/2014 10:07 AM <DIR> TextDocs
7 File(s) 1,704,717 bytes
8 Dir(s) 352,881,205,248 bytes free
The bin/ directory serves as a location where you can define your various startup scripts. The www is an example to start the express app as a web server.
The Missing script: "start" error occurs for multiple reasons: Missing a start script in the scripts section of your package. json file. Opening your IDE or shell in a directory that doesn't contain your package.
npm init -y. Will simply generate an empty npm project without going through an interactive process.
I had this same error when I was creating my First Node Project using express. But when i tried running it using
node ./bin/www // it will work
instead of
npm start
The server started at port 3000. you can check your app on localhost:3000 .
May be it can help some One else :)
Fwiw, I had the same error and it turned out to be that something was already running on port 3000. I mention this because the debug log mentioned nothing about this, just a similar error to yours. So maybe this will help somebody who comes across this post and happens to have the problem I did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With