I get this error when i run 'npm start'.
npm ERR! Missing script: "start"
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\USER\AppData\Local\npm-cache_logs\2022-04-
28T13_04_19_260Z-debug.log
CodePudding user response:
package.json
has various sections, scripts is one of them, which allows you to write npm script which we can run using npm run <script-name>
. The error you're getting is because your start script is missing in that section.
For a node app, your package.json
file should look similar to this.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"express": "^4.17.3"
}
}
In the above code, focus on the script section. The following line is missing in your package.json file.
"scripts": {
"start": "node app.js",
},
Add this line and you're good to go.
CodePudding user response:
You have to put what command you need npm to run when you give npm start.
You have to write node index.js in scripts.start in your package.json file