I am trying to setup a simple express server. I am using nodemon to start my development server But my app keeps crashing because it does not recognize the "babel-node" command.
The error output is
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,json
[nodemon] starting `babel-node index.js`
'babel-node' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
my package.json scripts are
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"startdev": "nodemon --ext js,json --exec babel-node index.js",
"start": "babel-node index.js"
}
and my dependencies and dev dependencies are
"dependencies": {
"express": "^4.17.1",
"express-graphql": "^0.12.0",
"graphql": "^15.4.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/preset-env": "^7.12.11",
"nodemon": "^2.0.7"
}
I tried testing it without nodemon, by using the regular node command and it runs as expected
$ npm run start
> [email protected] start
> babel-node index.js
Server is up...
My folder strucher is below
the contents of index.js are
const express = require("express");
const app = express();
app.listen(() => {
console.log("Server is up...")
})
I have also tried deleting my node_modules and package-lock.json files and reinstalling but still crashes.
Remove your node_modules and follow these steps:
Then, check the existence of these files:
node_modules/.bin/babel-node
node_modules/.bin/babel-node.cmd - windows only
node_modules/@babel/node/bin/babel-node.js
If everything looks good add to package.json: