Web applications that directly runs in the browser Backend is server side application and database Frontend is client side aplication
HTTP is hypertext transfer protocol which is used to load pages by using hypertext links. Node js has built in module http, which creates the http server to take request of client and give response back to client
Role of url in http is specifies the address which contains the information of required data.
https://localhost:5000/users/profile?username=mountblue https- secure connection with localhost localhost:5000-client connects to port 5000 users/profile-path,where the request is send username=mountblue,if username exists then that data is displayed on the given path
GET-Used to read the data from web server POST-To send data to server PUT- To modify data on server DELETE-To delete data on server at particular location PATCH-To modify a part of data on server
1xx-server received request 2xx-successful responses 3xx-User in different location,redirection error 4xx-Bad Request-cannot reach the page due to error at client side 5xx-errors on server side
GET-Used to read the data from web server POST-To send data to server PUT- To modify data on server DELETE-To delete data on server at particular location
200-ok
content length defines the size of message body in bytes send to recipient
path is full url whereas pathname is part of url,if path is empty then pathname will be empty
Node js is single threaded,open source,cross platform runtime environment for building fast and scalable server side and networking applications and it runs on v8 js engine where it uses event drivens and non blocking architecture
Callbacks handles the asynchronous i/o operations, it is possible by event driver architecture
core node modules bulit in modules in node js runtime environment,we can use them by using require(),there are many modules some are http,path,fs,os etc
http.createServer((request,response)=>{ response.end("Hello") })
url model example:const url = require('node:url') console.log(url.parse('https://developer.mozilla.org/en-US/docs/Web/API/Location/pathname#examples'))
npm is node package manager, it is library for javascript packages, it has command line tools used to install the packages whatever we want
It is key component of node js,it shows project dependencies,it contains metadata so it will be useful to understand about project,feature of package publishing,custom scripts etc
It is fast ,flexible web framework for nodejs, which helpuful in simplifies apis and it has added new features of middleware and routing which helps to organize code in simplfied form
const express=require('express') const app =express() app.get('/',(request,response)=>{response.send()})
script is object,it has many built in scripts and we can create custom scripts,where key is name of script and value is command that execute,it automates common task and improves workflow.
It has access on response object,request object and also next function makes changes if required, it can execute any code,it can process next() present in the stack
express.static()-serve static files such as html,css,javascript. express.json()-converts incoming request in json format express.urlencoded()-converts incoming request in urlencoded format
next() is callback functions,it executes next middleware function in stack,if not called it will stop there and next middleware or routers will not execute
serves static files from specified directory app.use(express.static('public'))
converts the given data into json format
Do you know about error handler middleware in Express and how is it different from other middlewares?
express comes with default error handler, if we want to have custom error handler for middleware is in this way (err,request,response,next) to handle errors and difference is it takes four arguments and handle errors of response and request
Extract from query object from response.object which was submitted to route by using request.query()