2
0
mirror of https://github.com/acepanel/acepanel.github.io.git synced 2026-02-04 09:13:09 +08:00
Files
acepanel.github.io/en/advanced/project/nodejs.md
2026-01-27 01:26:41 +08:00

2.1 KiB

Node.js Project

Node.js projects are used to deploy Express, Koa, NestJS, Next.js, and other Node.js applications.

Prerequisites

  1. Install Node.js runtime environment: Applications > Runtime Environment > Node.js
  2. Project source code

Deployment Steps

  1. Upload project code to server
  2. Install dependencies:
cd /opt/ace/project/myapp
npm24 install
  1. Create project:
    • Project Name: myapp
    • Project Directory: /opt/ace/project/myapp
    • Start Command: node24 app.js
  2. Enable Reverse Proxy

Start Command Examples

# Run directly
node24 app.js

# Use npm scripts
npm24 start

# Use npm run
npm24 run start:prod

# Set environment variables
NODE_ENV=production node24 app.js

# Specify port
PORT=3000 node24 app.js

Common Frameworks

Express

const express = require('express');
const app = express();

app.get('/', (req, res) => {
    res.send('Hello World');
});

app.listen(3000);

Start command: node24 app.js

NestJS

# Build
npm24 run build

Start command: node24 dist/main.js

Next.js

# Build
npm24 run build

Start command: npm24 start

Nuxt.js

# Build
npm24 run build

Start command: node24 .output/server/index.mjs

Process Management

AcePanel uses systemd to manage Node.js processes, automatically handling:

  • Automatic restart on process crash
  • Automatic startup on boot
  • Log recording

Environment Variables

It is recommended to use .env files to manage environment variables:

# .env
NODE_ENV=production
PORT=3000
DATABASE_URL=mysql://localhost:3306/mydb

Load using the dotenv package:

require('dotenv').config();

FAQ

Dependency Installation Failed

Try clearing cache and reinstalling:

rm -rf node_modules package-lock.json
npm24 install

Out of Memory

Increase Node.js memory limit:

NODE_OPTIONS="--max-old-space-size=4096" node24 app.js

Port Already in Use

Modify the port the application listens on, or check if another process is using it.