Skip to content

Commit

Permalink
test: add example with dotenvx to reproduce Unitech#3192 --update-env…
Browse files Browse the repository at this point in the history
… bug
  • Loading branch information
mkalygin committed Aug 24, 2024
1 parent 5c50ed4 commit 4e5fd17
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/dotenvx-pm2/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DE=dotenv
SH_DE=dotenv
DE_PM=dotenv
SH_DE_PM=dotenv
8 changes: 8 additions & 0 deletions examples/dotenvx-pm2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

To start http application in cluster mode:

```bash
$ pm2 start ecosystem.config.js
# OR
$ pm2 start http.js -i max
```
28 changes: 28 additions & 0 deletions examples/dotenvx-pm2/ecosystem.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
apps: [
{
name: 'forked_app',
script: './index.js',
env: {
PORT: 8001,
PM: 'pm2',
SH_PM: 'pm2',
DE_PM: 'pm2',
SH_DE_PM: 'pm2',
},
},
{
name: 'clustered_app',
script: './index.js',
instances: 2,
exec_mode: 'cluster',
env: {
PORT: 8002,
PM: 'pm2',
SH_PM: 'pm2',
DE_PM: 'pm2',
SH_DE_PM: 'pm2',
},
},
],
};
27 changes: 27 additions & 0 deletions examples/dotenvx-pm2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import http from 'http';

const {
PORT,
SH,
DE,
PM,
SH_DE,
SH_PM,
DE_PM,
SH_DE_PM,
} = process.env;

http.createServer((req, res) => {
res.writeHead(200);
res.end(JSON.stringify({
SH,
DE,
PM,
SH_DE,
SH_PM,
DE_PM,
SH_DE_PM,
}, null, 2));
}).listen(PORT, '0.0.0.0', () => {
console.log(`App listening on port ${PORT}`);
});
23 changes: 23 additions & 0 deletions examples/dotenvx-pm2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "dotenvx-pm2",
"version": "1.0.0",
"description": "Example usage of dotenvx with pm2",
"main": "index.js",
"type": "module",
"author": "Michael Kalygin",
"license": "MIT",
"scripts": {
"start:json:simple": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env -- ../../bin/pm2 start ecosystem.config.cjs",
"start:json:overload": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env --overload -- ../../bin/pm2 start ecosystem.config.cjs",
"start:pid:simple": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env -- ../../bin/pm2 start forked_app clustered_app",
"start:pid:overload": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env --overload -- ../../bin/pm2 start forked_app clustered_app",
"reload:json:simple": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env -- ../../bin/pm2 reload ecosystem.config.cjs --update-env",
"reload:json:overload": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env --overload -- ../../bin/pm2 reload ecosystem.config.cjs --update-env",
"reload:pid:simple": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env -- ../../bin/pm2 reload forked_app clustered_app --update-env",
"reload:pid:overload": "SH=shell SH_DE=shell SH_PM=shell SH_DE_PM=shell dotenvx run --env-file .env --overload -- ../../bin/pm2 reload forked_app clustered_app --update-env",
"delete": "../../bin/pm2 delete ecosystem.config.cjs"
},
"dependencies": {
"@dotenvx/dotenvx": "^1.10.2"
}
}

0 comments on commit 4e5fd17

Please sign in to comment.