DEV Community

Cover image for Node JS || Epress js || By Munisekhar Udavalapati
Munisekhar Udavalapati
Munisekhar Udavalapati

Posted on

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');
});
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

4.node js status codes

404===>not found
401===>unauthorised
400===>bad requst
200===>ok
201===>create
202===>accepted
Enter fullscreen mode Exit fullscreen mode

5.http methods

GET
PUT
POST
DELETE
Enter fullscreen mode Exit fullscreen mode

6.clinet filse send

const path=require('path');
app.use('/',(req,req,next)=>{
 res.sendFile(path.join(__dirname,'public','home.html'));
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)