Home > Software design >  Nuxt 3 : Difference nuxt start / nuxt preview?
Nuxt 3 : Difference nuxt start / nuxt preview?

Time:10-20

Is there a difference between nuxt start nuxt preview?

And is it correct to start a server with an ssr nuxt app in production mode with: npm run build (nuxt build)
npm run start (nuxt start) ?
For me, the docs are a little bit confusing, https://v3.nuxtjs.org/api/commands/preview/ "The preview command starts a server to preview your Nuxt application after running the build command."

CodePudding user response:

There are mainly 4 things:

  • nuxt dev, purely for development purposes
  • nuxt build for SSR or nuxt generate for SSG
  • nuxt preview to get a preview locally of what would the final bundle look like
  • nuxt start what should be running on the actual production server

At the end, Nuxt's team made this simple for us by detecting the platform you're pushing your code too. But at the end, you could have nuxt ship or nuxt yoloooo doing the exact same thing, it all depends of your own preferences.

Most of the defaults are adapting or overriding some possible mistakes by analyzing what are your project's settings and reacting accordingly.


Depending on where you deploy your app, you can get various behaviors as explained in the doc: https://v3.nuxtjs.org/getting-started/deployment

If you want to deploy your app on Heroku (SSR), your nuxt start command will look something like this

"scripts": {
  "build": "nuxt build",
  "start": "node .output/server/index.mjs"
}

as shown here: https://nitro.unjs.io/deploy/providers/heroku

If you're publishing your code to some SSG platform, it will usually use a "lighter Nginx/Apache server" for free and do basically the same as serve for your static assets (with nuxt start).


The only thing NOT to do is to ship a nuxt dev on production.

  • Related