This repository can be used as a convenient starting point for building
NODE REST API
's using TypeScript
on top of Express
web framework.
- Basic
JWT
authentication and account activation usingSMTP
- Repository pattern used to enable separation of concerns
MongoDB
- default repository implementation, should be easy to replace
- Install Node.js
- Install MongoDB
- Configure your SMTP service and enter your SMTP settings inside
.env.example
- Clone the repository
git clone --depth=1 https://github.com/maljukan/typescript-node-rest-starter.git <project_name>
- Install dependencies
cd <project_name>
npm install
- Configure your mongoDB server
# create the db directory
sudo mkdir -p /data/db
# give the db correct read/write permissions
sudo chmod 777 /data/db
- Start your mongoDB server (you'll probably want another command prompt)
mongod
- Build and run the project
npm run build
npm start
To access Swagger UI for available endpoints
http://localhost:3000/api-docs/#/
Pass token from /auth/login
when using protected endpoints (for example: getting all /users
) like Bearer <token>
- public:
/auth/login
,/auth/register
,/auth/activate
- protected:
/users
- Register
curl -d '{"email":"[email protected]", "password":"PASSWORD", "lname": "Doe", "fname": "John", "role": "guest", "username": "jdoe"}' -H "Content-Type: application/json" -X POST http://localhost:3000/auth/register
- Activation
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:3000/auth/activate/ACTIVATION_TOKEN
- Login
curl -i -d '{"email":"[email protected]", "password":"PASSWORD"}' -H "Content-Type: application/json" -X POST http://localhost:3000/auth/login
- GET /users
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer JWT_TOKEN_HERE" -X GET http://localhost:3000/users/
mongoimport --db heroes-db --collection users --file users.json --jsonArray
- Before running tests be sure to create a real
.env
file in root using the fields found in.env.example
npm run test
- Implement RBAC functionality
Integrate Swagger- Test coverage
The repository is based on Microsoft/TypeScript-Node-Starter