Problem Statement
How does JWT authentication work in Node.js?
Explanation
JWTs are signed tokens containing user data. The server verifies the token signature to authenticate users. JWTs are stateless and used for scalable authentication across APIs.
Code Solution
SolutionRead Only
import jwt from 'jsonwebtoken';
const token = jwt.sign({id:1},'secret',{expiresIn:'1h'});
const decoded = jwt.verify(token,'secret');