Npm start searching / bin / www in the wrong directory, how to update

So, I am following this tutorial here to get a personal / tutorial node.js project from where I would like to work and store on GitHub and ultimately host it on a live server or cloud hosting. It uses node.js, express, monk, mongoDB to configure the site. However, I have a persistent error that I did not find an answer to when I run "npm start".

Here is my command line window when I try to run "npm start" inside my express node project.

I know that: Error: I cannot find the module "C: \ Users \ username \ Desktop \ bin \ www" not where my bin \ www is located (it is inside the nodetest1 project).

C: \ Users \ username \ Documents \ GitHub \ TEDResources \ node.js \ nodetest1 <- the correct path

So why is npm looking at this wrong place and how do I update it to properly view my project folder? I searched my system and cannot find module.js anywhere. (using windows 7 x64) I also tried nuking node.js and express and start from scratch with no 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

> nodetest1@0.0.0 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! nodetest1@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the nodetest1@0.0.0 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 npm@1.4.28
3 info using node@v0.10.32
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose run-script [ 'prestart', 'start', 'poststart' ]
6 info prestart nodetest1@0.0.0
7 info start nodetest1@0.0.0
8 verbose unsafe-perm in lifecycle true
9 info nodetest1@0.0.0 Failed to exec start script
10 error nodetest1@0.0.0 start: `node ./bin/www`
10 error Exit status 8
11 error Failed at the nodetest1@0.0.0 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

> nodetest1@0.0.0 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
+4
source share
7 answers

Windows "autorun" - " " , . . laggingreflex , .

+2

, Node express. ,

node ./bin/www              // it will work

npm start

3000. localhost: 3000.
, - :)

+8

Fwiw, , , - 3000. , , . , , -, , , , , .

+4

, , . , , . app.js :

//var mongo = require('mongodb')
+1

, , , :

  • Ubuntu 14.04
  • npm v5.11.1
  • node v3.9.2

, , , .

, , (3000), :

sudo netstat -ep | grep 3000

.

, , un < nodetest1/bin/www ", 3000 3001, .

var port = normalizePort(process.env.PORT || '3001');

http://localhost:3001 .

: , netstat, , 3000:

sudo netstat -epa | grep 3000

ntop :

tcp        0      0 *:3000                  *:*                     ESCUCHAR    root       15508       2289/ntop

nodetest1 www .

, .

0

, :

npm install

:

npm start

0

In the app.js training file, be sure to specify the index object as follows:

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

This should fix the error.

Although the textbook author says, an error will be thrown if this line reads:

var index = require('./routes/routes');
0
source

All Articles