Skip to content

Commit

Permalink
单个 process 直接执行 ✅
Browse files Browse the repository at this point in the history
module.exports = process.env.PORT_ENV || 8080;
  • Loading branch information
xgqfrms committed Oct 15, 2021
1 parent 2939cd8 commit 74c4073
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ typings/
.next
.DS_Store

env.js
# env.js
6 changes: 3 additions & 3 deletions env-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// webpack.config.js
// const PORT_ENV = require('./env.js');
const PORT_ENV = require('./env.js');
// Error: Cannot find module './env.js'

// console.log('PORT_ENV =', PORT_ENV);
console.log('PORT_ENV =', process.env.PORT_ENV);
console.log('PORT_ENV =', PORT_ENV);
console.log('process.env.PORT_ENV =', process.env.PORT_ENV);

// 临时 current child process env
// PORT_ENV=666 node ./env-test.js
Expand Down
29 changes: 29 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// default
// const env = process.env.PORT_ENV || 8080;
// module.exports = env;

module.exports = process.env.PORT_ENV || 8080;

/*
// 单个 process 直接执行 ✅
$ PORT_ENV=777 node ./env-test.js
PORT_ENV = 666
process.env.PORT_ENV = 666
*/


/*
// && 多个 process ❌
$ PORT_ENV=777
$ node ./env-test.js
PORT_ENV = 8080
process.env.PORT_ENV = undefined
*/

0 comments on commit 74c4073

Please sign in to comment.