Andy J Andy J - 5 months ago 39
Javascript Question

How to control where NPM finds server.js?

I'm following this blog and in the section 4, they show how to execute and run an application. It's working as described.

Now, I'd like to put the file server.js, which is the entry point in a directory called app. The command npm start doesn't find it any more, though.

After some googling I've read that I'm supposed to put in the following line in the package.json, which I did.

"start": "app/server.js",

The problem is that it still can't find it and I can't really diagnose the issue. Is it because the entry point must be in the root? Does the start element need to be placed in a certain order in JSON file? Am I specifying the path incorrectly (I've tried "\" and "/" etc.)?


You're missing the call to node:

"start": "node app/server.js",

Also make sure to place the above line in the "scripts" section of package.json.

"scripts": {
  "start": "node app/server.js",