Servers and APIs

How to create a simple HTTP API with authentication with Node.js?

In this example we’ll see how to create an HTTP API with 3 main components: Signup, Login and a login-only route. Let’s start by setting up a new project and including Express for handling the routes, JSON Web Token to handle auto-expiring tokens, and bcrypt to encrypt user passwords. Initialize the new project in an empty folder. We’ll name the main file index.mjs to utilize top level awaits and have import/export functionality.