Search code examples
node.jsmongodbexpressnode-modulesnodemon

npm run test error Node.js


I am making an API using node.js and want to test some files. npm init runs fine and correctly installed packages such as mongoose and express. However, when I run npm run test-watch the terminal throws the following error:

[nodemon] 1.14.11
[nodemon] to restart at any time, enter rs
[nodemon] watching: *.*
[nodemon] starting 'npm test'
'npm' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...

Following are the contents of the package.json file:

"scripts": {
    "test": "mocha server/**/*.test.js",
    "test-watch": "nodemon --exec 'npm test'"
  }

The node path is added to the user paths. init runs successfully and installed packages as well. So I want to know if there is any error in the syntax.

Note: If you want to check any code, please let me know


Solution

  • This is because I am using the Windows OS, there was an error with the syntax:

    "test-watch": "nodemon --exec 'npm test'"
    

    The above code should be the following instead:

    "test-watch": "nodemon --exec \"npm test\""