Dev environment starts with this command:
nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"
How do i create a global variable (or process.env
variable) __DEV__ = true
?
Dev environment starts with this command:
nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"
How do i create a global variable (or process.env
variable) __DEV__ = true
?
You can either add "env"
property to nodemon.json
, like this:
...
"env": {
"__DEV__": "true"
}
Or you can prepend __DEV__="true"
to start
script in package.json
.
Both worked for me.
env
files and ignoring in the gitignore
file. –
Uptotheminute You can add a "nodemonConfig" property to package.json with your env info. Then execute nodemon in your scripts section.
"nodemonConfig": {
"restartable": "rs",
"ignore": [
"node_modules/**/node_modules"
],
"delay": "2500",
"env": {
"NODE_ENV": "development",
"NODE_CONFIG_DIR": "./config"
}
}
env
files and ignoring in the gitignore
file. –
Uptotheminute .env
is outside the scope of this question. –
Hypochlorite For windows: set __DEV__ = true&&nodemon -w src --exec \"babel-node src --presets es2015,stage-0\
"
If you don't want to handle the env variables in the nodemon call, you can do something like this.
Create a file called '.env' and put something like this in it:
DEV=true
Then in your application entry file put the following line in as early as possible:
require('dotenv').config();
I normally use the dotenv module on my projects.
We just need to create a .env
file and require the dotenv
module in our project:
.env
file:
__DEV__="true"
your-script.js
file:
require('dotenv').config();
console.log(process.env.__DEV__)
Creating .env
files is normally a good option since we can prevent to commit our environment files using .gitignore
just define in codes (server file) like this proccess.env.VARIABLE="true"
© 2022 - 2024 — McMap. All rights reserved.
__DEV__="true" nodemon -w src --exec \"babel-node src --presets es2015,stage-0\"
. It'll probably come in as a string, you'll have to parse it or rely on it's absence for truthiness/falsiness. – Caa