"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Node JS || Epress js || By Munisekhar Udavalapati

Node JS || Epress js || By Munisekhar Udavalapati

Published on 2024-11-06
Browse:958

Node JS || Epress js || By Munisekhar Udavalapati

Express js

  1. to write simple express js application

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'));
})
Release Statement This article is reproduced at: https://dev.to/munisekhar_udavapati/node-js-epress-js-by-munisekhar-udavalapati-1kh9?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

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