Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`npm start` complains "missing script: start", without running node

Tags:

node.js

npm

I have the following files in my NPM package:

package.json:

{
  "name": "npm-start",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

index.js

console.log('Hello world!');

When I try to run npm start, I get an error message:

> npm start
npm ERR! missing script: start

Okay, it's true: I don't have a "start" property in "scripts" object. But NPM's CLI Documentation claims this about npm start:

If no "start" property is specified on the "scripts" object, it will run node server.js.

Why is NPM failing me? Isn't it supposed to invoke node in this scenario? Am I missing something? (Of course, manually invoking node works fine).

In case it's relevant:

> npm -version
5.3.0
like image 376
sampathsris Avatar asked Mar 13 '26 11:03

sampathsris


1 Answers

As soon as I finished typing the question, I realized my error.

When "start" property is absent, NPM will invoke node with server.js. But I don't have a server.js. NPM checks under the hood for this server.js file, and fails if it's not present. Ideally though, NPM should have reported that server.js wasn't found. The current way of handling things is confusing.

As soon as you have a server.js file, npm start works fine.

like image 113
sampathsris Avatar answered Mar 15 '26 05:03

sampathsris