File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -151,3 +151,36 @@ Using the run script
151
151
152
152
``` npm start ```
153
153
154
+ ## 9. ` dotenv ` Package
155
+
156
+ ` dotenv ` allows for environment variables configuration, such as managing API keys and credentials.
157
+
158
+ Install ` dotenv `
159
+
160
+ ``` npm install dotenv ```
161
+
162
+
163
+ Edit the web server JavaScript file
164
+
165
+ ``` javascript
166
+ require (' dotenv' ).config ();
167
+
168
+ const express = require (' express' );
169
+ const app = express ();
170
+ const port = process .env .PORT ;
171
+
172
+ console .log (port); // 5000
173
+ ```
174
+
175
+ Create a ` .env ` file
176
+
177
+ ```
178
+ PORT=5000
179
+ ```
180
+
181
+ Re-run the web server and all should still work as before, only this time the the port number is not exposed in the JavaScript code.
182
+
183
+ > Don't forget to add your ` env ` file to the ` .gitignore `
184
+
185
+ [ Read more about the dotenv Package] ( https://www.npmjs.com/package/dotenv )
186
+
You can’t perform that action at this time.
0 commit comments