Skip to content

Commit

Permalink
Use environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hagopj13 committed Oct 25, 2019
1 parent fab2718 commit 687392e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=3000
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ node_modules

# package-lock.json (use yarn.lock instead)
package-lock.json

# Environment varibales
.env*
!.env*.example
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
"node": ">=12.0.0"
},
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"start": "cross-env NODE_ENV=production node src/index.js",
"dev": "cross-env NODE_ENV=development nodemon src/index.js",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prettier": "prettier --check **/*.js",
"prettier:fix": "prettier --write **/*.js"
},
"dependencies": {
"cross-env": "^6.0.3",
"dotenv": "^8.2.0",
"express": "^4.17.1"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions src/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const dotenv = require('dotenv');
const path = require('path');

dotenv.config({
path: path.join(__dirname, '../../.env'),
});

module.exports = {
env: process.env.NODE_ENV,
port: process.env.PORT,
};
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const app = require('./app');
const { port } = require('./config/config');

const port = 3000;
app.listen(port, () => {
console.log(`Listening to port ${port}`);
});
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,13 @@ create-error-class@^3.0.0:
dependencies:
capture-stack-trace "^1.0.0"

cross-env@^6.0.3:
version "6.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-6.0.3.tgz#4256b71e49b3a40637a0ce70768a6ef5c72ae941"
integrity sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag==
dependencies:
cross-spawn "^7.0.0"

cross-spawn@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -784,6 +791,11 @@ dot-prop@^4.1.0:
dependencies:
is-obj "^1.0.0"

dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

duplexer3@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
Expand Down

0 comments on commit 687392e

Please sign in to comment.