Last Updated Mar 06, 2023
Reading time: 3 minutes The An example error output is shown below: 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 The following tutorial shows how to fix this error in practice To run the command, you need to make sure that you have a 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.$ npm startnpm ERR! code ENOENTnpm ERR! syscall opennpm ERR! path node-app/package.jsonnpm ERR! errno -2npm ERR! enoent
npm start
command not working:package.json
file in your projectstart
script in the package.json
fileignore-script
config to false
1. Create a package.json file in your project
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 startnpm 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 -1node_modulespackage-lock.jsonpackage.jsonserver.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 startnpm 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-scriptstrue
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! 👋