How to fix npm start command not working

The npm start command is to start a JavaScript project or application. Sometimes, you might run into a situation where the npm start command isn’t working as expected.

An example error output is shown below:

$ npm start
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path node-app/package.json
npm ERR! errno -2
npm ERR! enoent 

This can be frustrating, especially if you’re new to JavaScript development and don’t know where to start troubleshooting.

Fortunately, there are three easy steps you can take to fix the npm start command not working:

  1. Create a package.json file in your project
  2. Write the start script in the package.json file
  3. Set the ignore-script config to false

The following tutorial shows how to fix this error in practice

1. Create a package.json file in your project

To run the command, you need to make sure that you have a package.json file in your project.

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'

You need to make sure that the package.json file is present from where you run the npm start command.

To do so, run the ls -1 command from the terminal. You should see package.json listed as shown below:

$ ls -1
node_modules
package-lock.json
package.json
server.js
...

When you don’t see the package.json file, then you can create one for your project using the npm init command:

npm init

The terminal will require you to fill some information about your project. Once done, a package.json file will be generated for you.

2. Check if the start script is defined

Next, you need to make sure that a start script exists inside the package.json file.

A common start script for most applications is as follows:

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

You need to write node followed by the name of the .js file you want to run as the content of the start script.

If you don’t have a start script as shown above, you might get another error as follows:

$ 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.

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

Once you have a start script in your package.json file, the npm start command should work.

3. Set the ignore-script config to false

If you see the start script is present inside your package.json file but npm start still not working, 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 true.

You can check the configuration by using the command below:

$ npm config get ignore-scripts
true

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 show some output. That means the command is now working.

Conclusion

This tutorial has shown you steps to resolve the npm start command not working.

To run npm start command successfully, you need to have a package.json file with a start script defined in your project’s directory.

You also need to make sure that the ignore-scripts configuration is set to false or you’ll receive no output.

I hope this tutorial is helpful. Until next time! 👋

Take your skills to the next level ⚡️

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

No spam. Unsubscribe anytime.