2021-10-11 12:57:54 +00:00
|
|
|
# Node.js server
|
|
|
|
|
2021-10-11 17:18:38 +00:00
|
|
|
Discover the Node.js server preset with Nitro to deploy on any Node hosting.
|
2021-10-11 12:57:54 +00:00
|
|
|
|
2021-10-11 17:18:38 +00:00
|
|
|
::list
|
2021-10-29 11:26:01 +00:00
|
|
|
|
2021-10-11 17:18:38 +00:00
|
|
|
- **Default preset** 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 debugging
|
|
|
|
::
|
2021-10-11 12:57:54 +00:00
|
|
|
|
2021-10-11 17:18:38 +00:00
|
|
|
::alert{icon=IconPresets}
|
|
|
|
Back to [presets list](/docs/deployment/presets).
|
|
|
|
::
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2021-10-29 11:26:01 +00:00
|
|
|
You can use the [Nuxt config](/docs/directory-structure/nuxt.config) to explicitly set the preset to use:
|
2021-10-11 12:57:54 +00:00
|
|
|
|
2021-10-29 11:26:01 +00:00
|
|
|
```js [nuxt.config.js|ts]
|
2021-10-11 12:57:54 +00:00
|
|
|
export default {
|
|
|
|
nitro: {
|
|
|
|
preset: 'server'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Or directly use the `NITRO_PRESET` environment variable when running `nuxt build`:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
NITRO_PRESET=server npx nuxt build
|
|
|
|
```
|
|
|
|
|
2021-10-29 11:26:01 +00:00
|
|
|
## Entry point
|
2021-10-11 12:57:54 +00:00
|
|
|
|
2021-10-29 11:26:01 +00:00
|
|
|
When running `nuxt build` with the Node server preset, the result will be an entry point that launches a ready-to-run Node server.
|
2021-10-11 12:57:54 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
node .output/server/index.mjs
|
|
|
|
```
|
|
|
|
|
2021-10-11 17:18:38 +00:00
|
|
|
## Example
|
2021-10-11 12:57:54 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ node .output/server/index.mjs
|
|
|
|
Listening on http://localhost:3000
|
|
|
|
```
|
|
|
|
|
2021-10-11 17:18:38 +00:00
|
|
|
## Server timings
|
2021-10-11 12:57:54 +00:00
|
|
|
|
2021-11-21 12:31:44 +00:00
|
|
|
You can enable the `nitro.timing` option to have the logs about the chunk loading and cold start performance.
|
2021-10-11 12:57:54 +00:00
|
|
|
|
2021-10-29 11:26:01 +00:00
|
|
|
```js [nuxt.config.js|ts]
|
2021-10-11 12:57:54 +00:00
|
|
|
export default {
|
|
|
|
nitro: {
|
|
|
|
preset: 'server',
|
|
|
|
timing: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ node .output/server/index.mjs
|
|
|
|
> Cold Start (3ms)
|
|
|
|
Listening on http://localhost:3000
|
|
|
|
> Load chunks/nitro/static (0ms)
|
|
|
|
> Load chunks/app/render (1ms)
|
|
|
|
> Load chunks/app/client.manifest (0ms)
|
|
|
|
> Load chunks/index (3ms)
|
|
|
|
> Load chunks/app/server (2ms)
|
|
|
|
> Load chunks/app/vue3 (0ms)
|
|
|
|
```
|