during npm start, facing issue. Shows error

HemLata Sharma 0 Reputation points
2024-07-13T17:01:07.73+00:00

While running npm start, terminal throws an error "missing script: start" even when I have already added the "start" into the script part. I am not able to see the output of Application.

This question is related to the following Learning Module

Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
1,666 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 65,571 Reputation points
    2024-07-13T18:04:53.14+00:00

    Try:

    npm run start

    0 comments No comments

  2. VarunTha 8,855 Reputation points Microsoft Vendor
    2024-07-15T12:55:14.9133333+00:00

    Hi HemLata Sharma,

    Thank you for reaching out to us on MS Q&A forum.

    As the Bruce (SqlWork.com) suggested, try running npm run start instead. Sometimes, npm start might not work as expected. Using npm run start can often resolve the issue.

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.


  3. HemLata Sharma 0 Reputation points
    2024-07-17T04:11:21.5066667+00:00

    Screenshot 2024-07-17 093839

    This kind of error I am receiving. I had inserted start in the script already, but still, it is showing this. Kindly check.

    0 comments No comments

  4. VarunTha 8,855 Reputation points Microsoft Vendor
    2024-07-17T10:56:46.3233333+00:00

    Hi HemLata Sharma,
    The difference between the two scenarios when running npm start lies in the location of the package.json file:

    Scenario 1 (Correct Path):

    • Path: C:\Users\Quadrant\Desktop\varun\node-essentials\node-dependencies\3-final-solution-exercise-package-json\package.json
    • Outcome: The command executes successfully.
    • Explanation: In this scenario, you are within the directory (3-final-solution-exercise-package-json) that contains the package.json file. When you execute npm start, npm checks the package.json file in the current directory for a start script. Since the package.json here includes "start": "node ./src/index.js" in its scripts section, npm runs node ./src/index.js as instructed. This results in the expected output, such as "Welcome to this application!".
      User's image

    Scenario 2 (Incorrect Path):

    • Path: C:\Users\Quadrant\Desktop\varun\node-essentials\node-dependencies\package.json
    • Outcome: The command fails with an error.
    • Explanation: In this scenario, you are one level above the directory (node-dependencies) that contains the package.json file. When you run npm start, npm looks for the start script within the package.json file in the current directory (node-dependencies). However, the package.json in this directory does not define a start script or any other scripts. Therefore, npm cannot find the start script it needs to execute and reports an error stating "Missing script: 'start'".

    User's image

    Summary:

    • npm start executes successfully when you run it from the directory containing the relevant package.json file with a defined start script.
    • If you attempt to run npm start from a directory where package.json either does not exist or does not specify a start script, npm will fail with an error indicating that the expected script is missing.

    To ensure npm start works correctly, always run it from the directory where the corresponding package.json file resides and includes the necessary script definitions.

    If you encounter any future issues, please feel free to contact us, and we will be pleased to assist you further.

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.