Using Nuxt programatically
You can use Nuxt programmatically to use it as a middleware giving you the freedom of creating your own server for rendering your web applications.
You might want to use your own server with your middleware and your API. That's why you can use Nuxt programmatically.
Nuxt Constructor
To see the list of options to give to Nuxt, see the configuration section.
const { loadNuxt, build } = require('nuxt')
// Check if we need to run Nuxt in development mode
const isDev = process.env.NODE_ENV !== 'production'
// Get a ready to use Nuxt instance
const nuxt = await loadNuxt(isDev ? 'dev' : 'start')
// Enable live build & reloading on dev
if (isDev) {
build(nuxt)
}
// We can use `nuxt.render(req, res)` or `nuxt.renderRoute(route, context)`
You can take a look at the nuxt-express and adonuxt starters to get started quickly.
Debug logs
If you want to display Nuxt logs, you can add the following to the top of your file:
process.env.DEBUG = 'nuxt:*'
Edit this page on GitHub
Updated at Mon, Feb 28, 2022
Leoš Literák
Trizotti
Clément Ollivier
Sébastien Chopin
Marcello Bachechi
Rodolphe
Thomas Underwood
Shek Evgeniy
felipesuri
Lukasz Formela
Hugo Torzuoli
Sylvain Marroufin
Kareem Dabbeet
tramplay
Daniel Roe
verebelyicsaba
Adam
Nate Butler
Sandra Rodgers
Arpit Patidar
Matthew Kuehn
Steven DUBOIS
Travis Lindsey
syagawa
Maxime
かる
Al Power
Florent Delerue
quanghm
José Manuel Casani Guerra
Unai Mengual
kazuya kawaguchi
Michael Lynch
Tomachi
pooya parsa
Meir Roth
Brett
Adam Miedema
Thomas Bnt
Kazuki Furukawa
Anthony Ruelle
Christophe Carvalho Vilas-Boas
Roman Harmyder