Posts

ToDo List

 APP.JS const express = require ( "express" ); const bodyparser = require ( "body-parser" ); const app = express (); var items = [ "buy food" , "cook food" , "write code" ] app . set ( "view engine" , "ejs" ); app . use ( bodyparser . urlencoded ({ extended : true })) app . get ( "/" , function ( req , res ){ var today = new Date (); var options = {   weekday : "long" ,   day : "numeric" ,   month : "long" }; var day = today . toLocaleDateString ( "en-US" , options ) res . render ( "list" , { kindofday : day , newlistitems : items }) }) app . post ( "/" , function ( req , res ){   var item = req . body . newitem ;   items . push ( item );   res . redirect ( "/" ); }) app . listen ( 3000 , function (){   console . log ( "server started at port 3000" ); }) LIST.EJS <! DOCTYPE html > < html lan...

colored heading

 app.js const express = require ( "express" ); const bodyparser = require ( "body-parser" ); const app = express (); app . set ( "view engine" , "ejs" ); app . get ( "/" , function ( req , res ){ var today = new Date (); currentday = today . getDay (); var day = "" ; switch ( currentday ) {   case 0 :     day = "sunday"     break ;   case 1 :     day = "monday"     break ;   case 2 :     day = "tuesday"     break ;   case 3 :     day = "wednesday"     break ;   case 4 :     day = "thursday"     break ;   case 5 :     day = "friday"     break ;   case 6 :     day = "saturday"     break   default :     console . log ( "its an error" + currentday ); }   res . render ( "list" , { kindofday : day }) }) app . listen ( 3000 , function (){   console . log ( "server...

action posting

 calci js const express = require("express"); const app = express(); app.get("/contact", function(req, res){   res.send("surajkurle2003@gmail.com"); }) app.get("/", function(req, res){   res.sendFile(__dirname + "/index.html"); }) app.post("/", function(req, res){   res.send("thanks for posting this") }) app.listen(3000, function(){   console.log("server started at port 3000"); }) HTML code <!DOCTYPE html> <html lang="en" dir="ltr">   <head>     <meta charset="utf-8">     <title>calculator</title>   </head>   <h1>my calculator</h1>   <body>     <form action="/" method="post">       <input type="text" name="numq" placeholder="first number">       <input type="text" name="num2" placeholder="second number">       <button t...

calculator

 Js code const express = require("express"); const app = express(); app.get("/", function(req, res){   res.sendfile(__dirname + "/index.html") }) app.listen(3000, function(){   console.log("server started at port 3000"); }); index.html <!DOCTYPE html> <html lang="en" dir="ltr">   <head>     <meta charset="utf-8">     <title>calculator</title>     <h1>calculator</h1>   </head>   <body>     <form action="index.html" method="post">       <input type="text" name="num1" placeholder="first num">       <input type="text" name="num2" placeholder="second num">       <button type="submit" name="submit">calculate</button>     </form>   </body> </html>

understanding and working with routes

 const express = require("express"); const app = express(); app.get("/", function(req, res){   res.send("hello suraj") }) app.get("/contact", function(req, res){   res.send("you can contact me at : surajkurle2003@gmail.com") }) app.get("/about", function(req, res){   res.send("my name is suraj and m the greatest coder") }) app.listen(3000, function(){   console.log("server started at port 3000"); })

handling requests and response

 const express = require("express"); const app = express(); app.get("/", function(request, response){   response.send("hello suraj") }) app.listen(3000, function(){   console.log("server started at port 3000"); })

creating first server with express.js

  const express = require("express"); const app = express(); app.listen(3000, function(){   console.log("server started at port 3000"); })