zeekExpress(app.js, package.json , demo.pug , index.js)


package.json


{
  "name""zeekexpress",
  "version""1.0.0",
  "description""package created while studying and exploring node and express",
  "main""app.js",
  "scripts": {
    "test""echo \"Error: no test specified\" && exit 1"
  },
  "author""Zeeshan",
  "license""ISC",
  "dependencies": {
    "express""^4.17.1",
    "pug""^3.0.2"
  }
}



app.js

// Express.js, or simply Express, is a back end web application framework for Node.js,.
 It is designed for building web applications and APIs.

//Download postman by https://www.postman.com/downloads/ .Postman is an application 
used for API testing. It is an HTTP client that tests HTTP requests, utilizing a 
graphical user interface, through which we obtain different types of responses that need 
to be subsequently validated.

// Static files are files that clients download as they are from the server.Static files
 are files that don't change when your application is running

// Pug is the middleman who plays a role to convert the injected data and translate it 
into html syntax(TEMPLATE).
// Download pug by https://expressjs.com/en/guide/using-template-engines.html now run
 command npm install pug.  And copy paste commands like app.use____ or app.set___.   



const express = require("express");
const path =require("path");
const app = express();
const port = 80;

//For serving static files.
app.use('/static',express.static('static-folder'));

//PUG STARTING POINT
//set template engine as pug
app.set('view engine''pug');

//set views directory
app.set('views',path.join(__dirname,"views"));
//PUG ENDING POINT

app.get("/demo",(req,res)=>{
    res.status(200).render("demo",{title:"Hey Zee",message:"I am using pug"})
});

app.get("/", (reqres=> {
    res.send("This is homepage of my first express app")
});
app.get("/about", (reqres=> {
    res.send("This is about page of my first express app")
});
app.post("/about", (reqres=> {
    res.send("This is post of about page of my first express app")
});
app.post("/this", (reqres=> {
    res.status(404).send("Page not found")
});

app.listen(port, () => {
    console.log(`Application is running at port ${port}`)
});






//TERMINAL


//.... INITIALISING NPM AS PACKAGE MANAGER........

// PS C:\Users\abc\Desktop\webpart\Complete Web Development Part\Express> npm init


// COMPUTER RESPONSE[

// This utility will walk you through creating a package.json file.
// It only covers the most common items, and tries to guess sensible defaults.
// See `npm help json` for definitive documentation on these fields
// and exactly what they do.
// Use `npm install <pkg>` afterwards to install a package and
// save it as a dependency in the package.json file.

//]


//..... Using NPM AS PACKAGE MANAGER..........


// Press ^C at any time to quit.
// package name: (express) zeekexpress
// version: (1.0.0)
// description: package created while studying and exploring node and express
// entry point: (index.js) app.js
// test command:
// git repository:
// keywords:
// author: Zeeshan
// license: (ISC)
// About to write to C:\Users\abc\Desktop\webpart\Complete Web Development Part\Express\package.json:


// COMPUTER RESPONSE[

// {
//   "name": "zeekexpress",
//   "version": "1.0.0",
//   "description": "package created while studying and exploring node and express",
//   "main": "app.js",
//   "scripts": {
//     "test": "echo \"Error: no test specified\" && exit 1"
//   },
//   "author": "Zeeshan",
//   "license": "ISC"
// }

//]


// Is this OK? (yes) yes

//............ INSTALL EXPRESS USING NPM...............


// PS C:\Users\abc\Desktop\webpart\Complete Web Development Part\Express> npm install express


// COMPUTER RESPONSE[

// npm notice created a lockfile as package-lock.json. You should commit this file.
// npm WARN zeekexpress@1.0.0 No repository field.
// + express@4.17.1
// added 50 packages from 37 contributors and audited 50 packages in 10.897s
// found 0 vulnerabilities

//]


//....... RUNNING  EXPRESS ON TERMINAL........

// PS C:\Users\abc\Desktop\webpart\Complete Web Development Part\Express> node app.js

// COMPUTER RESPONSE[

// Application is running at port 80

//]


//............ INSTALL PUG USING NPM...............

//PS C:\Users\abc\Desktop\webpart\Complete Web Development Part\Express>  npm install pug

// COMPUTER RESPONSE[

// npm WARN zeekexpress@1.0.0 No repository field.
// + pug@3.0.2
// added 42 packages from 16 contributors and audited 92 packages in 18.23s
// 7 packages are looking for funding
//   run `npm fund` for details
// found 0 vulnerabilities

//]




folder: views , file: demo.pug

html
  head
    titletitle
  body
    h1message


 folder:  static-folder ,    file: index.js

console.log('Zeek is smart');

Comments

Popular posts from this blog

INDEX OF ZEEK HTML,CSS and JS