PortGate

Blueprints · Node.js & Next.js

Production 15 min · systemd

Node systemd user unit

Stages a Node service that runs as a dedicated user with NoNewPrivileges.

Live config

Baked-in protections

Step 1 · ini

Service unit

/root/portgate-blueprints/node-app.service

Create the user and the app directory before you enable this.

[Service]
User=node
WorkingDirectory=/opt/app
EnvironmentFile=/opt/app/.env
ExecStart=/usr/bin/node server.js
Restart=on-failure
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=/opt/app

Step 2 · bash

Read-only check

/root/portgate-blueprints/node-unit-check.sh

Prints status. It does not change the service.

#!/bin/sh
set -eu
id "node" 2>/dev/null || echo "User node does not exist yet."