Skip to content

Commit 8c9c2ce

Browse files
committed
add helloWorldNode app
1 parent dc07ddc commit 8c9c2ce

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
everydayDiscount = 20
2+
weeekendDiscount=5
3+
diwaliDiscount=5

session 6/HelloWorldApp/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT_Number=3300

session 6/HelloWorldApp/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// or just write => require('dotenv').config();
2+
// which uses defult configs
3+
require('dotenv').config();
4+
const PortNumber = process.env.PORT_Number;
5+
module.exports = {
6+
PortNumber,
7+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('dotenv').config({ path: __dirname + '/.discountenv' });
2+
3+
console.log('diwali discount is: ', process.env.diwaliDiscount);

session 6/HelloWorldApp/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const envConfig = require('./configuration');
2+
const discountenvConfig = require('./discountConfig');
3+
const http = require('http');
4+
5+
console.log('port number is ' + envConfig.PortNumber);
6+
const port = envConfig.PortNumber || 3000;
7+
8+
const server = http.createServer((req, res) => {
9+
res.statusCode = 200;
10+
const msg = 'Hello Node!';
11+
res.end(JSON.stringify({ data: msg }));
12+
});
13+
14+
server.listen(port, () => {
15+
console.log(`Server running on http://localhost:${port}/`);
16+
});

session 6/HelloWorldApp/package-lock.json

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "heelonode",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "node index.js",
9+
"start:dev": "node index.js --watch"
10+
},
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"dotenv": "^16.0.0",
15+
"lodash": "^4.17.21"
16+
}
17+
}

0 commit comments

Comments
 (0)