Skip to content

Instantly share code, notes, and snippets.

@victorshkoda
Created February 20, 2020 03:39
Show Gist options
  • Save victorshkoda/c06a0e4a3f5bdc041c98302ea32926b2 to your computer and use it in GitHub Desktop.
Save victorshkoda/c06a0e4a3f5bdc041c98302ea32926b2 to your computer and use it in GitHub Desktop.
Expressjs server for nuxt project
const express = require('express')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const port = process.env.PORT || 8000
app.set('port', port)
// Import and Set Nuxt.js options
let config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
async function start() {
// Init Nuxt.js
const nuxt = new Nuxt(config)
// 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)
// console.log('Server listening on http://' + host + ':' + port) // eslint-disable-line no-console
}
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment