diff --git a/README.md b/README.md index 618300a..08c444c 100644 --- a/README.md +++ b/README.md @@ -287,7 +287,7 @@ bun install ```bash # Start server với PM2 -pm2 start ecosystem.config.js --env production +pm2 start ecosystem.config.cjs --env production # Hoặc start trực tiếp pm2 start server.js --name "charging-station-mock" --interpreter bun @@ -368,7 +368,7 @@ sudo certbot renew --dry-run | Command | Mô tả | |---------|-------| -| `pm2 start ecosystem.config.js` | Start với config file | +| `pm2 start ecosystem.config.cjs` | Start với config file | | `pm2 start server.js --name app` | Start với tên custom | | `pm2 list` | Xem danh sách processes | | `pm2 logs [name]` | Xem logs | @@ -386,9 +386,9 @@ sudo certbot renew --dry-run # Cách 1: Environment variable PORT=3200 pm2 start server.js --name "charging-station-mock" --interpreter bun -# Cách 2: Sửa ecosystem.config.js +# Cách 2: Sửa ecosystem.config.cjs # env_production: { PORT: 3200 } -pm2 start ecosystem.config.js --env production +pm2 start ecosystem.config.cjs --env production ``` --- diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs new file mode 100644 index 0000000..20d34c4 --- /dev/null +++ b/ecosystem.config.cjs @@ -0,0 +1,21 @@ +module.exports = { + apps: [ + { + name: 'charging-station-mock', + script: 'server.js', + interpreter: 'bun', + instances: 1, + autorestart: true, + watch: false, + max_memory_restart: '500M', + env: { + NODE_ENV: 'development', + PORT: 3100, + }, + env_production: { + NODE_ENV: 'production', + PORT: 3100, + }, + }, + ], +}; diff --git a/ecosystem.config.js b/ecosystem.config.js deleted file mode 100644 index 20d34c4..0000000 --- a/ecosystem.config.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - apps: [ - { - name: 'charging-station-mock', - script: 'server.js', - interpreter: 'bun', - instances: 1, - autorestart: true, - watch: false, - max_memory_restart: '500M', - env: { - NODE_ENV: 'development', - PORT: 3100, - }, - env_production: { - NODE_ENV: 'production', - PORT: 3100, - }, - }, - ], -}; diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 120000 index 0000000..594728c --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1 @@ +ecosystem.config.cjs \ No newline at end of file diff --git a/server.js b/server.js index fd9ef41..d2ec54e 100644 --- a/server.js +++ b/server.js @@ -1,13 +1,17 @@ import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import jsonServer from 'json-server'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + const server = jsonServer.create(); -const router = jsonServer.router(path.join(import.meta.dir, 'db.json')); +const router = jsonServer.router(path.join(__dirname, 'db.json')); // Serve static files từ folder public (images, etc.) const middlewares = jsonServer.defaults({ logger: true, - static: path.join(import.meta.dir, 'public'), + static: path.join(__dirname, 'public'), }); const port = process.env.PORT || 3100;