-1

I installed nodemon to devDependencies and set the script "start" : "nodemon server.js". However, when I do npm start, it throws me this error:

Error: Cannot find module 'C:\Users\win10\Desktop\nodemon\bin\nodemon.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! question-answer-rest-api@1.0.0 start: `nodemon server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the question-answer-rest-api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

My package.json

{
  "name": "question-answer-rest-api",
  "version": "1.0.0",
  "description": "Back end project for practice",
  "main": "server.js",
  "scripts": {
    "start": "nodemon server.js"
  },
  "keywords": [
    "Express",
    "Nodejs",
    "Mongoose",
    "Api"
  ],
  "author": "Cihan Özcan",
  "license": "MIT",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "nodemon": "^2.0.7"
  }
}

I also filled in server.js and tried that way but it didn't work.

My server.js file

const express = require('express');

const app = express();

const PORT = 5000

app.listen(PORT, () => {
    console.log(`Server started on port ${PORT}`)
})

There are no any file in the folder. I couldn't find similar error in SO. I installed nodemon as global and checked the global environment in pc. There is no problem with it.

What is the problem ?

Cihan Özcan
  • 103
  • 3
  • 13
  • I tried this in Windows and in an empty node:14 docker container and it works just fine. I cannot reproduce your issue. – Wyck Jun 11 '21 at 18:48

1 Answers1

-3

Try

npm uninstall nodemon

Then

npm install -g nodemon

It should works

Kevin B
  • 94,570
  • 16
  • 163
  • 180
  • 1
    I don't think the intent was ever to install nodemon globally. The point is that the script should have worked, and indeed it *does* work on a clean system. So something is fishy with the asker's setup. – Wyck Jun 11 '21 at 18:44
  • 5
    I downvoted because this answer smuggles in the idea of installing nodemon globally, which is not necessary to solve your problem. Although _uninstalling_ an existing nodemon may very well have solved the problem. So it's half plausibly correct, but half misleading. Other readers may not wish to install nodemon globally to solve a similar problem. – Wyck Jun 11 '21 at 18:51