Skip to content

This application is a simple backend REST API server that facilitates user account management (i.e.: user registration, login, etc.), implements caching via redis, and saves its data to MongoDB.

Notifications You must be signed in to change notification settings

eriegz/user-account-management-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Account Management TypeScript

This is a sample backend REST API server that provides simple user account management (i.e.: user account registration, login, etc.), implements request caching via redis, and saves its data to MongoDB.

Prerequisites:

Node.js dependencies:

Before you can run the application, ensure that you've installed all of the necessary Node.js dependencies:

  • nvm install 16.3.1
  • npm i -g typescript ts-node
  • npm i
  • npm run build

...or to automatically re-build when watched files change:

  • npm run build-dev

Third party services:

Next, this application talks to redis and Mongo servers. To spin up instances of these on your local machine, follow these steps:

How to run:

Note: Ensure you've completed all of the "prerequisites" listed above first.

To run this application in "single execution mode" (i.e.: in production):

  • ensure that your environment has the NODE_ENV env variable set to one of the following: staging, preprod, or production
  • npm run start

...or to run it in "hot-reloading" mode (i.e.: for developers):

  • npm run dev

Note: the above will automatically pass NODE_ENV=dev to the application, which will point to Mongo and redis instances on localhost.

How to use:

To try out the REST API, you can copy-paste any of the following cURL request examples into your terminal, or an application such as Postman.

Note: for any endpoints that require authentication, you'll need to hit the /login endpoint first, then use the token value that's passed back to you in the Cookie response header.

Login endpoint:


curl --location --request POST 'localhost:3000/api/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "YOUR_USERNAME_HERE",
    "password": "YOUR_PASSWORD_HERE"
}'

User CRUD endpoints:


Create user:

curl --location --request POST 'localhost:3000/api/user/register' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "YOUR_USERNAME_HERE",
    "password": "YOUR_PASSWORD_HERE"
}'

Read user:

curl --location --request GET 'localhost:3000/api/user/YOUR_USERNAME_HERE' \
--header 'Cookie: token=REPLACE_THIS_WITH_YOUR_VALID_JWT_TOKEN'

Update user:

curl --location --request PUT 'localhost:3000/api/user/YOUR_USERNAME_HERE' \
--header 'Content-Type: application/json' \
--header 'Cookie: token=REPLACE_THIS_WITH_YOUR_VALID_JWT_TOKEN' \
--data-raw '{
    "password": "YOUR_PASSWORD_HERE"
}'

Delete user:

curl --location --request DELETE 'localhost:3000/api/user/YOUR_USERNAME_HERE' \
--header 'Cookie: token=REPLACE_THIS_WITH_YOUR_VALID_JWT_TOKEN'

About

This application is a simple backend REST API server that facilitates user account management (i.e.: user registration, login, etc.), implements caching via redis, and saves its data to MongoDB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published