Node, Express, TypeScript and MongoDB with Authentication. Containerised with Docker & Docker Compose.
To run production ready app:
docker compose down -v && docker compose up -d --build
Access at: http://localhost:8080/
To run local dev version:
npm i && npm run dev
Access at: http://localhost:1337/
You will need an .env
file:
API_PORT=1337
MONGODB_URL=mongodb://mongoadmin:mongopassword@localhost:27017/mydatabase?authSource=admin
MONGO_INITDB_ROOT_USERNAME=mongoadmin
MONGO_INITDB_ROOT_PASSWORD=mongopassword
AUTH_SECRET=secret
The .env.prod
should look like this (note the difference in the connection string because MongoDB should be on the same 'network' as the API):
API_PORT=8080
MONGODB_URL=mongodb://mongoadmin:mongopassword@mongo:27017/mydatabase?authSource=admin
MONGO_INITDB_ROOT_USERNAME=mongoadmin
MONGO_INITDB_ROOT_PASSWORD=mongopassword
AUTH_SECRET=secret
Register with the following credentials in the body:
{
"email": "vitaliy@krynv.dev",
"password": "fred",
"username": "krynv"
}
Login with the following credentials in the body:
{
"email": "vitaliy@krynv.dev",
"password": "fred"
}
List all users (must be logged in)
Update the given user's username (must be logged in and owner), with the following request body:
{
"username": "krynv25"
}
Update the given user from the database (must be logged in and owner)