-1

I am trying to use the npm start command but I don't have the correct "start" script in my package.json. Can anyone please tell me the correct way to add it?

I have tried adding "start": "node server.js" to my scripts in package.json but that throws up an error:

> node server.js

internal/modules/cjs/loader.js:589
    throw err;
    ^

Error: Cannot find module 'C:\Users\Aristophanes\server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
    at Function.Module._load (internal/modules/cjs/loader.js:513:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:308:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aristophanes@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the aristophanes@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Aristophanes\AppData\Roaming\npm-cache\_logs\2018-11-10T11_34_37_097Z-debug.log

So it can't find a server.js file. Can anyone elaborate what file exactly I'm supposed to be looking for to add to the "start" script? Package.json:

{
  "name": "aristophanes",
  "version": "1.0.0",
  "description": "",
  "main": ".eslintrc.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC"
}
Aristophanes
  • 475
  • 1
  • 9
  • 21
  • It can't find C:\Users\Aristophanes\server.js because there is no server.js. What are you trying to start? – Estus Flask Nov 10 '18 at 11:42
  • Could you please share your directory structure. This should work as you describe as long as you have a server.js file next to your package.json. – tenor528 Nov 10 '18 at 11:42

1 Answers1

0

Try to change "main": "server.js" in your package.json

Edit: You have to define the file name as main which contains your server.listen callback. Also you can start running with node [your-server-file].js If your file name is index.js node finds it automatically, no need the main part.

lependu
  • 1,160
  • 8
  • 18
  • 1
    Edited. Also note that the `Error: Cannot find module 'C:\Users\Aristophanes\server.js'` says there is no server.js in the directory. So you are either in the wrong directory, or you named your file something else than server.js. – lependu Nov 10 '18 at 11:43