Skip to main content

Deployment

Node.js deployment is the default Analog output preset for production builds.

When running npm run build with the default preset, the result will be an entry point that launches a ready-to-run Node server.

To start up the standalone server, run:

$ node dist/analog/server/index.mjs
Listening on http://localhost:3000

Environment Variables

You can customize server behavior using following environment variables:

  • NITRO_PORT or PORT (defaults to 3000)
  • NITRO_HOST or HOST

Built-in Presets

Analog can generate different output formats suitable for different hosting providers from the same code base, you can change the deploy preset using an environment variable or vite.config.ts.

Using environment variable is recommended for deployments depending on CI/CD.

Example: Using BUILD_PRESET

BUILD_PRESET=node-server

Example: Using vite.config.ts

import { defineConfig } from 'vite';

export default defineConfig({
plugins: [
analog({
nitro: {
preset: 'node-server',
},
}),
],
});

Deploying with a Custom URL Prefix

If you are deploying with a custom URL prefix, such as https://domain.com/`basehref`/ you must do these steps for server-side-data-fetching, html markup and assets, and dynamic api routes to work correctly on the specified basehref.

  1. Instruct Angular on how recognize and generate URLs. Create a new file app.config.env.ts.
import { ApplicationConfig } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';

export const envConfig: ApplicationConfig = {
providers: [{ provide: APP_BASE_HREF, useValue: '/basehref/' }],
};
  1. Update the app.config.ts file to use the new file.
import { mergeApplicationConfig } from '@angular/core';
import { envConfig } from './app.config.env';

export const appConfig = mergeApplicationConfig(envConfig, {
....
});
  1. In CI production build
  # sets the base url for server-side data fetching
export VITE_ANALOG_PUBLIC_BASE_URL="https://domain.com/basehref"
# prefixes all assets and html with /basehref/
npx nx run appname:build:production --baseHref='/basehref/'
  1. In production containers specify the env flag NITRO_APP_BASE_URL.
NITRO_APP_BASE_URL="/basehref/"

Given a vite.config.ts file similar to this:

    plugins: [
analog({
apiPrefix: 'api',

Nitro prefixes all API routes with /basehref/api.