Commands

Nuxt.js comes with a set of useful commands, both for development and production purpose.

List of Commands

CommandDescription
nuxtLaunch a development server on localhost:3000 with hot-reloading.
nuxt buildBuild your application with webpack and minify the JS & CSS (for production).
nuxt startStart the server in production mode (After running nuxt build).
nuxt generateBuild the application and generate every route as a HTML file (used for static hosting).

You should put these commands in the package.json:

"scripts": {
  "dev": "nuxt",
  "build": "nuxt build",
  "start": "nuxt start",
  "generate": "nuxt generate"
}

Then, you can launch your commands via npm run <command> (example: npm run dev).

Development Environment

To launch Nuxt in development mode with the hot reloading:

nuxt
// OR
npm run dev

Production Deployment

Nuxt.js lets your choose between 2 modes to deploy your application: Server Rendered or Static Generated.

Server Rendered Deployment

To deploy, instead of running nuxt, you probably want to build ahead of time. Therefore, building and starting are separate commands:

nuxt build
nuxt start

The package.json like follows is recommended:

{
  "name": "my-app",
  "dependencies": {
    "nuxt": "latest"
  },
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start"
  }
}

Note: we recommend putting .nuxt in .npmignore or .gitignore.

Static Generated Deployment

Nuxt.js gives you the possibility to host your web application on any static hosting.

To generate our web application into static files:

npm run generate

It will create a dist folder with everything inside ready to be deployed on a static hosting.

If you have a project with dynamic routes, take a look at the generate configuration to tell nuxt.js how to generate these dynamic routes.

When generating your web application with nuxt generate, the context given to data() and fetch() will not have req and res.

Caught a mistake or want to contribute to the documentation? Edit this page on GitHub!