Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node . and npm start don't work

Tags:

The title says most of the problem. When I try to run node . I get:

    module.js:340     throw err;           ^ Error: Cannot find module 'static-favicon'     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:902:3 

There seems to be no modules folder actually. I'm just running express in an empty directory

npm works fine however. This is with a fresh express install if it matters. Any help would be awesome, thanks!

the full error messages:

 new-host-2:~ Brennan$ cd Desktop/ new-host-2:Desktop Brennan$ mkdir test4 new-host-2:Desktop Brennan$ cd test4 new-host-2:test4 Brennan$ express -e     create : .    create : ./package.json    create : ./app.js    create : ./public    create : ./public/javascripts    create : ./public/images    create : ./public/stylesheets    create : ./public/stylesheets/style.css    create : ./routes    create : ./routes/index.js    create : ./routes/users.js    create : ./views    create : ./views/index.ejs    create : ./views/error.ejs    create : ./bin    create : ./bin/www     install dependencies:      $ cd . && npm install     run the app:      $ DEBUG=test4 ./bin/www  new-host-2:test4 Brennan$ node app.js  module.js:340     throw err;           ^ Error: Cannot find module 'static-favicon'     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> (/Users/Brennan/Desktop/test4/app.js:3:15)     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 Function.Module.runMain (module.js:497:10) new-host-2:test4 Brennan$ npm start app.js npm ERR! Error: ENOENT, open '/Users/Brennan/Desktop/test4/node_modules/app.js/package.json' npm ERR! If you need help, you may report this *entire* log, npm ERR! including the npm and node versions, at: npm ERR!     <http://github.com/npm/npm/issues>  npm ERR! System Darwin 12.4.0 npm ERR! command "node" "/usr/local/bin/npm" "start" "app.js" npm ERR! cwd /Users/Brennan/Desktop/test4 npm ERR! node -v v0.10.26 npm ERR! npm -v 1.4.7 npm ERR! path /Users/Brennan/Desktop/test4/node_modules/app.js/package.json npm ERR! code ENOENT npm ERR! errno 34 npm ERR!  npm ERR! Additional logging details can be found in: npm ERR!     /Users/Brennan/Desktop/test4/npm-debug.log npm ERR! not ok code 0 new-host-2:test4 Brennan$ forever app.js warn:    --minUptime not set. Defaulting to: 1000ms warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms  module.js:340     throw err;           ^ Error: Cannot find module 'static-favicon'     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> (/Users/Brennan/Desktop/test4/app.js:3:15)     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 Function.Module.runMain (module.js:497:10) error: Forever detected script exited with code: 8 
like image 536
Bren Avatar asked Jun 20 '14 19:06

Bren


People also ask

Why my npm command is not working?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

Does npm start use node?

If the "scripts" object does not define a "start" property, npm will run node server. js . Note that this is different from the default node behavior of running the file specified in a package's "main" attribute when evoking with node . As of [email protected] , you can use custom arguments when executing scripts.


2 Answers

After using the express-generator to generate the node application, you need to install the dependencies for the project. This is done via:

$ npm install 

Once this is done, you can start the app using npm:

$ npm start 

By default, the express generated apps state this as the start command for npm (you can view this in the package.json file):

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

So to execute the same thing via the command line, you would run:

$ node ./bin/www 
like image 159
dylants Avatar answered Oct 23 '22 07:10

dylants


I had the same issue after running the express-generator on a non-empty directory with some node modules already installed in node_modules, especially express itself. Simply nuke the folder, reinstall all your dependencies and you should be good to go:

rm -rf ./node_modules npm install npm start 

EDIT: Tuns out that at some stage in the process I had installed serve-favicon and saved that to the local package.json. Looks like the express generator failed to add that dependency. Therefore:

npm install serve-favicon --save npm start 
like image 31
Jan Michael Auer Avatar answered Oct 23 '22 06:10

Jan Michael Auer