How to fix npm start command not working

How to fix npm start command not working for your project

Posted on July 11, 2021

The npm start command is used to run the start command written inside your project’s package.json file.

When you don’t have the package.json file in the current working directory, your console will return a no such file or directory error:

$ npm start
npm ERR! enoent ENOENT: no such file or directory, open '/package.json'

When your package.json file doesn’t have the start command under the scripts property, then NPM will run node server.js instead.

When you run the npm start command, you may encounter an error saying that the start script is missing:

$ npm start
npm ERR! Missing script: "start"

This is because while you have a package.json file in your application, the start script is not defined. For most applications, the start script may look as follows:

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

The content of the start script may vary, but it must always be located inside the scripts property.

If you see the start script is present inside your package.json file but still can’t run the script, you need to check the console output.

If there’s no output at all, then you may have the ignore-scripts NPM configuration set to false.

You can check the configuration by using the command below:

$ npm config get ignore-scripts

If the command above returns true, then you need to set the config as false using the following command:

npm config set ignore-scripts false

Once the config has been set to false, try to close and open the console again.

This time, the npm start command should work.

Related articles:

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.