Tackle the Error “NPM start not working”

JavaScript is a highly powerful language to create the design to improve the interactivity of websites and applications. Almost all websites have many elements that are created by developers and programmers that make the website interactive for the users. When working with JavaScript, programmers also work on node.js, which is known as a JavaScript runtime environment. Various projects are designed using node. It is ideal for designing scalable network applications. It is an open-source and cross-platform backend environment of JavaScript. While NPM is the package manager for node.js modules and packages. When working with node.js, you may encounter “NPM start not working”.

The error seems annoying, it happens to all of us. But this error is not as complex as it looks. We at Tutopal provide you with a helping hand to drag you out of the error message. Before proceeding to the solution section, let’s check out why npm stopped working

Why your NPM is not working?

If your current directory doesn’t have a package.json file, you get the following error in the console

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

When you try to check if your package.json file has a start script present inside it. You get the error warning when you execute the npm start command

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

It occurs because there is no start script defined while having a package.json file in the app. For many applications, you can see the start script that is similar to the below script

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

Though the start script content can be a bit different, you need to know that it is always found in the script property.

The solution to Fix the Error “NPM start not working”

In order to use the npm start command, you need to add a start script in your package.json file. The first thing to do is to write npm init in the terminal by navigating the package.json file. It begins the package.json file creation process. Once done, you just need to provide basic information like the name of the project and file name.

For instance, you use ‘App.js’ as your file name that can be typed for the ‘entry point’. To accept the defaults, you need to just press ‘Enter’ after selecting the best suitable option.

package name: (mata) dev 

[version: (1.0.0) 

[description: App.js 

[entry point: (.mongorc.js) App.js 

[test command: 

[git repository: 

[keywords: 

author: 

license: (ISC) 

About to write to /Users/mata/package.json: 

{

"dependencies": { 

"app-root-path": "^3.0.0" 

},

"name": "dev", 

"version": "1.0.0", 

"description": "App.js", 

"main": "App.js", 

"devDependencies": {}, 

"scripts": { 

"test": "echo "Error: no test specified" && exit 1" 

},

"author":" 

"license": "ISC" 

}

Is this OK? (yes) yes

The next step is to find and open the file location. The package.json file is saved in the terminal by the directory you are using for your project. The ‘App.js’ file and the user directory file are exactly in the same place. Incorporate the start script in the object called ‘scripts’ in the package.json file. This works wonderfully as you can simply activate the npm start command.

{ "dependencies": {

"app-root-path": "^3.0.0" 

}, 

"name": "dev", 

"version": "1.0.0", 

"description":"", 

"main": "App.js",

"devDependencies": {}, 

"scripts": { 

"test": "echo "Error: no test specified" && exit 1", 

"start": "node App.js"

 }, 

"author":"", 

"license": "ISC" 

}

After this, you can again run the npm start. It runs smoothly.

Conclusion

In this article, we shed light on the solution to fix the error “NPM start not working”. We also discussed why you get this error. The solution is simple and easy to implement.

I hope you find it helpful!

Leave a Reply

Your email address will not be published. Required fields are marked *