Now when I run the command:
"nodemon server.js" or just "nodemon"
it gives the following error:
module.js:549
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\node_modules\nodemon\bin\nodemon.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Below is my "server.js" file in case you need for reference.
var express = require("express");
var bodyParser = require("body-parser");
var morgan = require("morgan");
var path = require("path");
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(function (req, es, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, POST");
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
next();
});
app.use(morgan("dev"));
app.use(express.static(__dirname + "/app"));
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname + "/index.html"));
});
app.listen(8080);
console.log(">>>>> App is Running <<<<<");
Use npx to solve the error "'nodemon' is not recognized as an internal or external command, operable program or batch file", e.g. npx nodemon server. js or install the package globally by running npm install -g nodemon and make sure your PATH environment variable is set up correctly.
Just executing command nodemon index. js will run your project. But if you install Nodemon locally by command npm install nodemon then you have to specify the script. If you name it as start then npm run start or npm start will trigger the server to run.
remove node_modules in your project and than install reagain nodemon module, run below commands;
rm -rf node_modules
npm install -g npm@latest
npm i nodemon
In my case it was same issue I solved it by mentioned method hope it will help you so in package.json in script tag
"start":"nodemon index.js"
and in terminal with this command run
nodemon start
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With