To check if token expired using this JWT library in Node.js, we get the expiration timestamp and compare it to the current date and time.
For instance, we write
const isTokenExpired = (token) =>
Date.now() >= JSON.parse(atob(token.split(".")[1])).exp * 1000;
to get the token’s expiration timestamp in milliseconds with
JSON.parse(atob(token.split(".")[1])).exp * 1000
Then we compare it to the current timestamp returned by Date.now.
If the current timestamp is bigger than the token’s timestamp, then the token expired.