Express js
npm init
npm install express
const express=require('expreass'); const app=express(); app.use('/',(req,res,next)=>{ rse.send('succuss'); }) app.listen(3000,()=>{ console.log('port 3000 is success'); });
2.write JWT token authentication.
npm install jsonwebtoken
const jwt=require('jsonwebtoken'); const newToken=jwt.sign({name:'sekhar',userId:'sekhar_32'},process.env.sec_jwt_key,{expiresIn:'5m'}); console.log(newToken); const jwtVerify=jwt.verify(newToken,process.env.sec_jwt_key); console.log(jwtVerify);
3.password encryption in node js
npm install bcrypt
const bcrypt=require('bcrypt'); const password='ex_password'; const hashPassword=bcrypt.hash(password); const verifyPassword=bcrypt.compare(password,hashPassword); console.log(verifyPassword); //true
4.node js status codes
404===>not found 401===>unauthorised 400===>bad requst 200===>ok 201===>create 202===>accepted
5.http methods
GET PUT POST DELETE
6.clinet filse send
const path=require('path'); app.use('/',(req,req,next)=>{ res.sendFile(path.join(__dirname,'public','home.html')); })
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3