mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-15 10:24:50 +00:00
55 lines
1.5 KiB
Markdown
55 lines
1.5 KiB
Markdown
# Node.js Server
|
|
|
|
Discover the Node.js server preset with Nitro to deploy on any Node hosting.
|
|
|
|
::list
|
|
|
|
- **Default output format** if none is specified or auto-detected <br>
|
|
- Loads only the required chunks to render the request for optimal cold start timing <br>
|
|
- Useful for deploying Nuxt apps to any Node.js hosting
|
|
::
|
|
|
|
## Entry point
|
|
|
|
When running `nuxt build` with the Node server preset, the result will be an entry point that launches a ready-to-run Node server.
|
|
|
|
```bash
|
|
node .output/server/index.mjs
|
|
```
|
|
|
|
## Example
|
|
|
|
```bash
|
|
$ node .output/server/index.mjs
|
|
Listening on http://localhost:3000
|
|
```
|
|
|
|
## Configuring defaults at runtime
|
|
|
|
This preset will respect the following runtime environment variables:
|
|
|
|
- `NITRO_PORT` or `PORT` (defaults to `3000`)
|
|
- `NITRO_HOST` or `HOST` (defaults to `'0.0.0.0'`)
|
|
- `NITRO_SSL_CERT` and `NITRO_SSL_KEY` - if both are present, this will launch the server in HTTPS mode. In the vast majority of cases, this should not be used other than for testing, and the Nitro server should be run behind a reverse proxy like nginx or Cloudflare which terminates SSL.
|
|
|
|
### Using PM2
|
|
|
|
To use `pm2`, use an `ecosystem.config.js`:
|
|
|
|
```js [ecosystem.config.js]
|
|
module.exports = {
|
|
apps: [
|
|
{
|
|
name: 'NuxtAppName',
|
|
exec_mode: 'cluster',
|
|
instances: 'max',
|
|
script: './.output/server/index.mjs'
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
## Learn more
|
|
|
|
:ReadMore{link="https://nitro.unjs.io/deploy/node.html" title="the Nitro documentation for node-server preset"}
|