1. How does JWT authentication work in Node.js?
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.
import jwt from 'jsonwebtoken';
const token = jwt.sign({id:1},'secret',{expiresIn:'1h'});
const decoded = jwt.verify(token,'secret');