Posts

Showing posts with the label express

Route Parameter and query string in express (Nodejs)

Route Parameter and query string in express (Nodejs).   import express from 'express' ; const app = express (); const port = process . env . PORT || '3000' // : it is use for showing dynamic values . app . get ( '/delete/student/:id' ,( req , res ) => {     console . log ( req . params );     res . send ( `Student Deleted ${ req . params . id } successfully.` ); }) app . get ( '/product/:category/:id' ,( req , res ) => {     console . log ( req . params );       res . send ( `Product Category is ${ req . params . category } and id is ${ req . params . id } ` );     // desturcture     // const {id , category } = req.params     // res.send(`Product Category is ${category} and id is a ${id}`); }); app . get ( '/product/mobile/:year/and/:month' ,( req , res ) => {     const { year , month } = req . params     res . send ( `Product Year is ${ year } and months is ${ month ...

Making router in express (Node js)

 Making router in express (Node js) 1. first file app.js import express from 'express' ; import stu from './routes/student.js' // const stu  = require('./routes/student.js'); //old pattern const app = express (); const port = process . env . PORT || '3000' //load Router Modules. app . use ( '/student' , stu ); app . listen ( port ,() => {     console . log ( "Server Connected Successfully." ); }); 2. student.js import express from 'express' ; const router = express . Router (); // All students routes.. router . get ( '/all' , ( req , res ) => {     res . send ( "All Students" ); }) router . post ( '/create' , ( req , res ) => {     res . send ( 'Create Studends.' ); }) router . put ( '/update' , ( req , res ) => {     res . send ( 'Update student' ); }) router . delete ( '/delete' ,( req , res ) => {     res / send ( 'Delete student'...

Routing in express (Node )

                                    ✔    Routing in express  (Node ) import express from 'express' ; const app = express (); const port = process . env . PORT || '3000' app . get ( '/' ,( req , res ) => {     res . send ( "Hello Friends " ); }); app . all ( '/sab' ,( req , res ) => {     res . send ( "Hello All  " ); }); app . all ( '/api/*' ,( req , res ) => {     res . send ( "Page Not found" ); }) //string pattern path. app . get ( '/ab?cd' ,( req , res ) => {     res . send ( 'it showing abcd and acd' );     //it's showing abcd and acd . }); //Regular expression // app.get(/a/,(req,res)=>{ //     res.send('woking when type a with any data'); //     //not write with single '' quote with /a/ // }); app . get ( '/oncecallback/' ,( req , res ) =...

First express js application

                                      First express js application  // First application in express const express = require ( 'express' ); const app = express (); const port = process . env . PORT || 3000 app . get ( '/' ,( req , res ) => {     res . send ( 'Hello World' ); }); app . listen ( port ,() => {     console . log ( 'Server Connected Successfully.' ); });