BIENVENUE10valid for the first month only! on all offersView plans
Skip to content
← Knowledge base

Deploy a Node.js application

Set up environment variables, the startup script and deploy via Git to your instance.

Deploy a Node.js application

Deploying a Node.js application on your onesubnet.com instance comes down to three steps: pull the code, configure environment variables, and start the process.

Cause / The problem

An application that starts and then crashes, or that cannot find its configuration variables, usually suffers from a missing .env file, an incorrect startup script, or dependencies that are not installed.

Solution

  1. Connect to your instance via SSH or the panel terminal.
  2. Pull the code from Git:
    git clone https://github.com/your-org/your-app.git
    cd your-app
    Or upload your files via SFTP into the application folder.
  3. Install dependencies:
    npm install        # or: bun install / yarn install
  4. Create the .env file at the project root with your environment variables:
    NODE_ENV=production
    PORT=3000
    DATABASE_URL=postgresql://user:password@db-paris.onesubnet.com:5432/mydb
    JWT_SECRET=your_long_random_secret
    Never commit this file to Git (add .env to .gitignore).
  5. Start the application directly to verify it boots:
    npm start
    # or: node index.js / node dist/main.js
  6. Put the application into production with PM2 so it runs in the background and restarts automatically:
    npm install -g pm2
    pm2 start npm --name "my-app" -- start
    pm2 save
    pm2 startup          # enables startup on system boot
  7. For later updates via Git:
    git pull origin main
    npm install
    pm2 restart my-app
  8. Check the logs if a crash occurs:
    pm2 logs my-app --lines 50

For a clean setup, create a PM2 ecosystem.config.js file that defines env and env_production, then start with pm2 start ecosystem.config.js --env production.

Related products

oneSubnet

French hosting provider in Paris. High-performance game and voice servers.

SERVICES

Resources

LEGAL

All systems operational