xgqfrms / app-node-env

APP_ENV & one cli tools for customize env of APP
https://app-node-env.xgqfrms.xyz
MIT License
3 stars 0 forks source link

git ignore bug #12

Open xgqfrms opened 2 years ago

xgqfrms commented 2 years ago

git ignore bug

  1. ignore env
  2. delete env
  3. create env

❌ git ignore !== github ignore

xgqfrms commented 2 years ago
// webpack.config.js
const PORT_ENV = require('./env.js');
// Error: Cannot find module './env.js'

console.log('PORT_ENV =', PORT_ENV);

https://github.com/xgqfrms/xgqfrms/blob/master/env-test.js

image

xgqfrms commented 2 years ago

solution

直接写入到 node.js process.env variable ?

动态写入

  1. process.env.PORT_ENV = 8090;

默认值

  1. const port = process.env.PORT_ENV ?? 8080;
const port = parseInt(process.env.PORT, 10) || 5000;

const port = parseInt(process.env.PORT_ENV , 10) || 8080;
xgqfrms commented 2 years ago

npm set process.env variable

https://blog.logrocket.com/customizing-node-js-env-files/

xgqfrms commented 2 years ago

npm linux bash script set process.env variable All In One 作者:xgqfrms 链接:https://www.cnblogs.com/xgqfrms/p/15405706.html 来源:https://www.cnblogs.com 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 ©xgqfrms 2012-2021 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问! 原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!

xgqfrms commented 2 years ago

set-process-env / set-node-process-env

https://www.npmjs.com/package/set-process-env

https://www.npmjs.com/package/set-node-process-env 作者:xgqfrms 链接:https://www.cnblogs.com/xgqfrms/p/15405706.html 来源:https://www.cnblogs.com 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 ©xgqfrms 2012-2021 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问! 原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!