@@ -311,6 +311,86 @@ console.log(`Addition of number 10 and 12 : ${add.Addition(10, 12)}`);
311311console.log(` Subtration of number 14 and 12 : ${sub.subtration(14, 12)}` );
312312```
313313
314+ ## Day 7 - HttpModules
315+
316+ 1 . Node js are providing some of the inbuild module which we help to devlop Node apllication.<br />
317+ 2 . Http module is one of inbuild module which will help to create web server for web application.<br />
318+ 3 . It will help to see the output in browser<br /><br />
319+
320+ 4 . Importing the http module <br />
321+ ``` ruby
322+ const http = require (' http' )
323+ ```
324+
325+ 5 . Now yoou need to create the server, with the input paramter of function of req and res. <br />
326+ ``` ruby
327+ // create the server which will take input of req and output as rs
328+ http.createServer(function(req, res){
329+
330+ ```
331+ 6 . At the end you can mention on which port it will listen.
332+
333+ ``` ruby
334+ }).listen(4000 , () => console.log(" Your application is running on Port 4000" ));
335+ ```
336+
337+ 7 . At the end you can see the full code where we can write it like.
338+ ``` ruby
339+ // Importing the http module
340+ const http = require (' http' )
341+
342+ // create the server which will take input of req and output as rs
343+ http.createServer(function(req, res){
344+
345+
346+ // Adding requst header
347+ res.writeHead(200 , {' Content-Type' : ' text/html' });
348+
349+ // Pass query string in URL localhost: 4000 / 123
350+ var qs = req.url;
351+
352+ res.write(" <h1>hello Satya<h1>" + qs);
353+
354+ // you need to complete the response here.
355+ res.end();
356+
357+ }).listen(4000 , () => console.log(" Your application is running on Port 4000" ));
358+ ```
359+ 8 . you can stop server using ctrl + c
360+
361+ ### Nodemon
362+
363+ 1 . In above code if you are changing anything in code you to stop server and rerun again.
364+ 2 . To avoid thatyou need to install nodemon.
365+ 3 Nodemon is a utility that will monitor for any changes in your source and automatically restart your server
366+ 4 . Just use nodemon instead of node to run your code, and now your process will automatically restart when your code changes.
367+ 5 . Installing nodemon
368+ > npm install -g nodemon <br />
369+
370+ run the node application <br />
371+
372+ > nodemon index.js <br />
373+
374+ <b >*** If above will not work follow the below process</b > <br />
375+
376+ First,Install Nodemon as ``` npm install --save nodemon ``` <br />
377+
378+ Than in package.json write the followings <br />
379+
380+ ``` ruby
381+ " scripts" : {
382+ " server" : " nodemon server.js"
383+ },
384+ ```
385+ Now in terimnal check for.
386+
387+ ``` ruby
388+ npm run server
389+ npm run server HttpNodemon .js
390+ ```
391+
392+
393+
314394
315395## Day 10 - ExpressJs
316396
0 commit comments