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 Thu, Feb 9, 2023
Paiva
Florian Reuschel
Sébastien Chopin
Daniel Roe
Rishi Raj Jain
Clément Ollivier
Savas Vedova
Steven Soekha
Vinícius Alves
Kareem Dabbeet
Valentín Costa
Ryan Skinner
Alex Hirzel
Ajeet Chaulagain
René Eschke
Nico Devs
Muhammad
Nazaré da Piedade
Naoki Hamada
Tom
Yann Aufray
Anthony Chu
Nuzhat Minhaz
Lucas Portet
Richard Schloss
bpy
Antony Konstantinidis
Hibariya
Jose Seabra
Eze
Florian LEFEBVRE
Lucas Recoaro
Julien SEIXAS
Hugo
Sylvain Marroufin
Spencer Cooley
Piotr Zatorski
Vladimir Semenov
Harry Allen
kazuya kawaguchi
Unai Mengual
Hyunseung Lee
Alexandre Chopin
pooya parsa
Nick Medrano
Mosaab Emam
Iljs Путлер Капут
Heitor Ramon Ribeiro
Nero
Yoon Han
Ikko Eltociear Ashimine
FamCodings
Ayouli
F. Hinkelmann
felipesuri
Christophe Carvalho Vilas-Boas
Leoš Literák
Trizotti