Mehdi Coding
Mehdi Coding

Reputation: 21

Nodemon with express and nuxt

I want to watch for files changes for an express app where I use Nuxt as rendering engine, but I am not able to get it work as when I run nodemon app.js it keeps rebuilding, and when running nodemon app.js --ignore \".nuxt\" it does not work

below is my code for express:

const { loadNuxt, build } = require('nuxt')

const app = require('express')()
const isDev = process.env.NODE_ENV !== 'production'
const port = process.env.PORT || 3000

// Import Routes
const apiRoute = require('./routes/api');


async function start() {

  app.use('/api', apiRoute);

  // We get Nuxt instance
  const nuxt = await loadNuxt(isDev ? 'dev' : 'start')

  // Render every route with Nuxt.js
  app.use(nuxt.render)

  // Build only in dev mode with hot-reloading
  if (isDev) {
    build(nuxt)
  }
  // Listen the server
  app.listen(port, '0.0.0.0')
  console.log('Server listening on `localhost:' + port + '`.')
}

start()

Upvotes: 0

Views: 1891

Answers (2)

Leotrim Lota
Leotrim Lota

Reputation: 81

In this case you need only to add --watch in your package.json

  "scripts": {
    "dev": "nuxt --watch",

Upvotes: 0

just add in package.json:

"scripts": {
       "dev": "cross-env NODE_ENV=development nodemon app.js --watch server",
        ....
  },

Upvotes: 2

Related Questions