Reputation: 340
I have set up several Nuxt applications using ExpressJS on Nuxt version 2.12.x, but the option is no longer present in the configuration setup with npx create-nuxt-app
.
Previously, create-nuxt-app
created a file server/index.js
like this:
const express = require('express')
const consola = require('consola')
const { Nuxt, Builder } = require('nuxt')
const app = express()
// Import and Set Nuxt.js options
const config = require('../nuxt.config.js')
config.dev = process.env.NODE_ENV !== 'production'
async function start() {
// Init Nuxt.js
const nuxt = new Nuxt(config)
const { host, port } = nuxt.options.server
await nuxt.ready()
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
}
// Give nuxt middleware to express
app.use(nuxt.render)
// Listen the server
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
})
}
start()
However, using create-nuxt-app
with Nuxt version 2.13.2 no longer creates this server/index.js
file. I have tried creating a server/index.js
file and also server.js
and neither change the default behavior of the nuxt
command.
How can I configure my nuxt app to use Express other than downgrading to 2.12?
Upvotes: 1
Views: 934
Reputation: 847
Please go through this below link:
https://nuxtjs.org/api/configuration-servermiddleware/
You just need to define the parameter named serverMiddleware in the nuxt.config.js file, and the value of this parameter is the path to your server/index.js file.
Upvotes: 1