Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build before restarting the node.js (express) server using Nodemon

I am using nodemon to watch the changes to the server files and restart the server. It works fine when the script is ec5

nodemon ./server.js

but I want to write the script in ec6 and compile using babel doing the same thing but building before the server is restarted.

package.json

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "babel src --out-dir dist",
    "serve": "npm run build && node dist/index.js", 
    "serve-dev": "nodemon dist/index.js"
  },
  "dependencies": {
    "babel-preset-env": "^1.7.0",
    "express": "^4.16.4"
  },
  "devDependencies": {
    "@babel/cli": "^7.0.0-rc.1",
    "@babel/core": "^7.0.0-rc.1",
    "@babel/node": "^7.0.0-rc.1",
    "@babel/preset-env": "^7.0.0-rc.1",
    "nodemon": "^1.18.3"
  }
like image 479
Digvijay Upadhyay Avatar asked Apr 09 '26 19:04

Digvijay Upadhyay


1 Answers

Run with babel-node. (I can see it's already installed as dev dependency)

"serve-dev": "nodemon --exec babel-node src/index.js"

(assumed that src/index.js is your entry point of your app)

like image 181
Ritwick Dey Avatar answered Apr 11 '26 08:04

Ritwick Dey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!