2

I am a novice in NodeJS and I am trying to start with express and express-generator. I have installed express with the command:

C:\project>npm install -g express

Then I've installed the express-generator module:

C:\project>npm install -g express-generator

Then I create a folder for the project and install de dependencies:

C:\project\express> nodetest1
C:\project\nodetest1>npm install

Everything works fine there, but the problem appears when I try to start the server, with the command:

C:\project\nodetest1>npm start

It seems that the service starts but it closes as soon as it starts, result:

> nodetest1@0.0.0 start C:\project\nodetest1
> node ./bin/www

C:\project\nodetest1>

When I try to open localhost:3000 it doesn't work. I have search on the net and I haven't found a solution for it, could someone guide me on how to solve this problem?

Thank you.

Update 1:

After having reinstalled node.js and followed the steps proposed below, now I get an error:

C:\wamp\www\mynewapp>npm start

> mynewapp@0.0.0 start C:\wamp\www\mynewapp
> node ./bin/www


npm ERR! mynewapp@0.0.0 start: `node ./bin/www`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the mynewapp@0.0.0 start script.
npm ERR! This is most likely a problem with the mynewapp 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 mynewapp
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\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\wamp\www\mynewapp
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! syscall spawn
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! mynewapp@0.0.0 start: `node ./bin/www`
npm ERR! Exit status -1
npm ERR!
npm ERR! Failed at the mynewapp@0.0.0 start script.
npm ERR! This is most likely a problem with the mynewapp 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 mynewapp
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\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\wamp\www\mynewapp
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:\wamp\www\mynewapp\npm-debug.log
npm ERR! not ok code 0

C:\wamp\www\mynewapp>
Naschtok
  • 33
  • 1
  • 2
  • 5
  • Are you going through the "Thinkster.io" angular tutorial by any chance?? – Goodword Feb 26 '15 at 16:11
  • As a coincidence I have discovered that website yesterday, this problem is not linked to any tutorial of that website. After formatting the PC I solved the problem, I have never known why did that happen. – Naschtok Feb 27 '15 at 16:54

3 Answers3

2

you can solve this issue easily. Go to "packages.json" file then change start :

"scripts": {
    "start": "node ./bin/www"
}

and make it "start": "node app.js". Then run the command npm start and the project is not going to work. Now go back and change start again to "start": "node ./bin/www" which is the default value in Express and run the command, npm start. It worked for me.

Beachhouse
  • 4,972
  • 3
  • 25
  • 39
jess
  • 23
  • 7
1

You need to check in your package.json what npm start is doing. It should have the command to start your app, and it should have a part looking something like this:

"scripts": {
    "start": "node app.js"
},

the app.js should have been created by the generator, but given the steps that you described it seems you forgot to generate the app. Try this:

express mynewapp
cd mynewapp
npm install
npm start
fmsf
  • 36,317
  • 49
  • 147
  • 195
1

try http://www.npmjs.com/package/gennode it's a very easy code generator module for Nodejs projects. The crud controller, route, test and documentation will be automatically generated for you. so you just have to focus on the functionality that makes your sever unique.

Nathan Mersha
  • 749
  • 5
  • 6