Posts

Showing posts from September, 2022

How to use git.

  Use git . Make account on github. after click on + for create repository  and name .  It' s only first time follow steps.  git config --global user.name "Type Your name" git config --global user.email "Type Your email" git touch .gitignore //touch for make file and if folder than use slash / git init git add .  // after add use (dot) git commit -m "Initial Commit " git status git remote add origin --Paste your ssh key or https key -- git push origin master  **Code after changes in file *** ** git status git add . git commit -m "add files" git push origin master  // Make branches .. git branch   //show branches  git branch login-system  //for create branches  git checkout login-system //  insert in branches. //after make login-branch. git status git add . git commit -m "code paste in login-branch" git push origin login-system  //for merge with master branch. git checkout master // insert in master branches git m...

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'...

destructuring in javascript

destructuring in javascript  : The  destructuring assignment  syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables. Example :: first:: Object const myObjet = {     name: "Harry",     className: "first",     subject:"Hindi",     state:"Rajasthan",     pincode:300000, } const {name,className, subject,asd,pincode} = myObjet; console.log(name,asd,pincode); Output::Harry undefined 300000 Example::Second:: Object const myObjext = {     name:"Harry",     className: "five",     subject:"Hindi",     state:"rajasthan",     pincode:123123 } function showObject({name, className, subject,state,pincode}){     const message = "my name is "+name + " I am study in "+className +     " i like " + subject +" subject most. my state is  "+ state +" ok."     console.log(message...

Rest parameters in JavaScript

Rest parameters  The rest parameter syntax allows a function to accept an indefinite number of arguments as an array.  Only the last parameter in a function definition can be a rest parameter. function first(firtstar,...argments){     console.log(firtstar,argments); } first(1,3,3,4,5); Output::1 [ 3, 3, 4, 5 ]

CallBack function in javaScript.

 ðŸ‘Œ  CallBack function in javaScript.  function callback(){     console.log("This is a my first call"); } function test(name,call){     console.log("My name is "+ name);     call(); //same arguments name/ } test("anil",callback); //same name of callback function;

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.' ); });

Express application generator in node js .

 ðŸ‘Œ    Express application generator in node js .    1. For install application generator .     npx express-generator --view=ejs chapter3     2. After write this.        npm install    3. after this run  && remember to change folder name as  chapter3       please write our folder name instead of chapter3.         SET DEBUG=chapter3:* & npm start

How to set up babel for express-js .

 ðŸ‘‰ How to set up babel for express-js .  Browser not understand es6 code so use babel. 1. Firstly install express  2. After install express js than   npm install -D @babel/cli @babel/core @babel/preset-env  3. Make a file with .babelrc and Paste this code.  { "presets": ["@babel/preset-env"] }  4. Write this code in Package.json in Script  "scripts": { "start": "babel index.js -w --out-dir prd", "dev-serve": " nodemon prd/index.js" },  5. After this run in terminal  npm start //This is use for showing compiler data one by one.  6. and open a another terminal and write  npm run dev-serve  --------------------------If Not have index.js file -------------------------------------------------------- 7.  index.js code for showing data Hello word import express from 'express'; const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () =...

Connect mongodb to node js using mongoose .

https://mongoosejs.com/docs/5.x/docs/index.html get form data ..veson 5.13.15 please remember. const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/harryKart', {useNewUrlParser: true, useUnifiedTopology: true}); const db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function() { console.log(`we're connected!`) }); const kittySchema = new mongoose.Schema({ name: String }); kittySchema.methods.speak = function speak() { const greeting = "My Name is " + this.name ; console.log(greeting); }; const Kitten = mongoose.model('Kitten', kittySchema); const harryKitten = new Kitten({ name: 'Harry' }); const harryKitten2 = new Kitten({ name: 'Harry2' }); // console.log(harryKitten.name); // 'Silence' // harryKitten.speak(); harryKitten.save(function (err, harryKitten) { if (err) return conso...