This application accompanies the blog post, Your First Node Express App with Typescript.
To set up the application, first clone the repo. Then, install the dependencies by running yarn:
yarn
To start the server, run:
yarn run start
The server should now be running on port 3000.
The server only has a few endpoints:
GET /
—Returns "hello world"POST /users
—Adds a username/password pair to an in-memory user storePOST /login
—Validates a username/password agains the in-memory user store
The GET endpoint can be viewed simply by navigating to http://localhost:3000
. You should see "Hello world".
You can use curl to send requests to the two POST endpoints. Here are some examples:
To create a new user with username foo
and password bar
:
curl -d "username=foo&password=bar" -X POST http://localhost:3000/users
# User created
To see the response of a malformed user registration request:
curl -d "username=foo&password= " -X POST http://localhost:3000/users
# Bad username or password
To log in with our previously-created user foo
:
curl -d "username=foo&password=bar" -X POST http://localhost:3000/login
# Success
To see the response of a failed login request:
curl -d "username=foo&password=wrong" -X POST http://localhost:3000/users
# Login failed