It is a project to help you to create an api using nodejs, with this kit, you will avoid starting from the very beginning using authentication and MongoDB as a database.
To use it, you will need to have a mongodb server and change it's config on config.js
into src
folder.
If you'll run it into a Docker using the project's docker-compose file, you don't need to take care with it (mongo server).
config.js
module.exports = {
database: 'mongodb:https://localhost:27017/node-auth'
};
OR For docker users:
module.exports = {
database: 'mongodb:https://database/node-auth'
};
1 - git clone https://github.com/abdalla/node-auth.git
2 - npm install
3 - npm start
1 - git clone https://github.com/abdalla/node-auth.git
2 - npm install
3 - docker-compose up
To run the tests you don't need to have mongodb installed.
Running tests to make sure everything is working good.
It is pretty simple...
npm test
or to get coverage statistics
npm run test-cover
Used to create the first user (admin)
Verbose: POST
https://localhost:3000/api/setup
Response:
{
"success": true,
"user": { user information }
}
Used to authenticate the user and get the token used to comunicate with the other routes.
Verbose: POST
https://localhost:3000/api/auth
Header:
Content-Type: application/json
Body:
{
"email": "[email protected]",
"password": "admin"
}
Response:
{
"success": true,
"message": "enjoy",
"token": "<token>"
}
Used to get all users.
Verbose: GET
https://localhost:3000/api/users
Header:
x-access-token: "<token>"
Response:
{
"success": true,
"users": []
}
Used to get a specific user.
Verbose: GET
https://localhost:3000/api/user/{userId}
Header:
x-access-token: "<token>"
Response:
{
"success": true,
"user": { user information }
}
Used to create a new user.
Verbose: POST
https://localhost:3000/api/user
Header:
Content-Type: application/json
x-access-token: "<token>"
Body:
{
"user": {
"name": "user full name",
"userName": "user name",
"password": "password",
"email": "[email protected]",
"admin": false
}
}
Response:
{
"success": true,
"user": { user information }
}
Used to update an user information (except password).
Verbose: PUT
https://localhost:3000/api/user
Header:
Content-Type: application/json
x-access-token: "<token>"
Body:
{
"user": {
"_id": REQUIRED,
"name": "user full name (optional)",
"userName": "user name (optional)",
"email": "[email protected] (optional)",
"admin": false(optional)
}
}
Response:
{
"success": true,
"user": { user information }
}
Used to change the user password.
Verbose: PUT
https://localhost:3000/api/userpassword/{userId}
Header:
Content-Type: application/json
x-access-token: "<token>"
Body:
{
"currentPassword": "currentPassword",
"newPassword": "newPassword"
}
Response:
{
"success": true,
"user": { user information
}
}
Used to delete an user.
Verbose: DELETE
https://localhost:3000/api/user/<userId>
Header:
x-access-token: "<token>"
Response:
{
"success": true,
"user": { user information }
}
Express - The most popular Node framework ( thinking to change to koa )
Mongoose - Interact with our MongoDB database
Morgan - Log requests to the console so we can see what is happening
body-parser - Get parameters from our POST requests
jsonwebtoken - Create and Verify our JSON Web Tokens
bluebird - Promise
Mocha - The testing framework
Chai - Gives you some useful tools for testing, such as expect/should functions.
mongodb-memory-server - Allows you to run Mongoose in-memory instead of connecting to a persistent database.
Factory-girl - For creating factories for your models.
Faker - For creating randomized data
Supertest - For performing requests in your tests
Istanbul - JS code coverage tool
This project will be migrate to Typescript soon!