Node Excercise


Exercise N1 var http = require('http'); http.createServer(function(req, res){ res.writeHead(200, {'Content-Type': 'text/html'}); res.end('Excercise 1 Output \nHello World!'); }).listen(8080, ()=> console.log('starting 8080'));

Output:- Hello World!


Exercise N2: Creating New Modules var http = require('http'); var dt = require('./myModule'); http.createServer(function(req, res){ res.write("The date and time are currently: " + dt.myDate()); res.end(); }).listen(8080, ()=> console.log('starting 8080'));

Output:- The date and time are currently:: Thu Jan 27 2022 09:48:35 GMT-0600 (Central Standard Time)


Exercise N3: Run the code shown below and then enter the following in your Browser: http://localhost:8080/apples http://localhost:8080/pears http://localhost:8080/strawberries var http = require('http'); http.createServer(function(req, res){ res.write(req.url); res.end(); }).listen(8080, ()=> console.log('starting 8080'));

Output:- /apples /pears /strawberries


Exercise N4: Simple Adder

Solution:- Please follow below guidelines to run the code. 1. Click on the below github link and download the complete source code. Github Link 2. Replace the below 'scripts' code in package.json file. "scripts": { "start": "set NODE_ENV=development && nodemon w3d6_number_quiz/app.js" }, 3. Open the terminal in VSCode, go to the node folder and run following commands a. $ npm install b. $ npm start 4. Open the browser and copy paste the link http://localhost:8080/SimpleAdder.html;