This repository contains a simple demo API built with NodeJS. The API is used to manage users in a MongoDB database.
This application was developed using ExpressJS. MongoDB was used for persisting data with Mongoose as ORM.
- Start up your terminal (or Command Prompt on Windows OS).
- Clone the repository to a local directory.
- Navigate to the project folder using
cd UserManageron your terminal (or command prompt) - Linux users may either install both docker and docker-compose by running the
install_linux.shfile in the project root from the terminal as a user with administrator privileges, or they may install by using the instructions below. - Visit https://docs.docker.com/engine/installation/ to install the appropriate version of docker for your operating system.
- Visit https://docs.docker.com/compose/install/ to install the appropriate version of docker-compose for your operating system.
- Confirm installation of docker and docker-compose with the commands
docker --versionanddocker-compose --versionrespectively. - You may modify the
.envfile in your root directory as described in.envfile or you may leave the preset values as-is. - After this, you can then start the containers by running the command:
docker-compose upfrom the terminal in the project root directory as a user with administrator privilege.
- Start up your terminal (or Command Prompt on Windows OS).
- Ensure that you have
nodeandmongodbinstalled on your PC. - Clone the repository to a local directory.
- Navigate to the project folder using
cd UserManageron your terminal (or command prompt) - After cloning, install the application's dependencies with the command
npm install. - Modify the
.envfile in your root directory as described in.envfile. Variables such as DB_URL (which must be a mongoDB URL) and PORT are defined in the .env file and it is essential you set the values of the variables to match your local setup environment before running the application. You may ignore the variables in the database variables section. They are not required when not using containers.
PORT=3000
DB_URL='mongodb://john:doe@localhost:27017/databaseName'
- Ensure the mongodb service is running.
- After this, you can then start the server with the command:
npm run start-local.
To ensure that your installation is successful you'll need to run tests.
The command: npm test makes this possible. It isn't functional right now, but once it's done you'll be notified via the README.
The API only has one endpoint which is the /users endpoint for saving users to the database. The endpoint works with the HTTP verbs: POST, GET, PUT, DELETE.
POST/users- INPUT:
name: John Doe
email: [email protected]
password: johndoe
- HTTP Status:
201: created - JSON data
{
"_id": "59071791b0lkscm2325794",
"name": "John Doe",
"email": "[email protected]",
"password": "johndoe",
"__v": 0
}GET/users
[
{
"_id": "59071791b0lkscm2325794",
"name": "John Doe",
"email": "[email protected]",
"password": "johndoe",
"__v": 0
}
]GET/users/:id
{
"_id": "59071791b0lkscm2325794",
"name": "John Doe",
"email": "[email protected]",
"password": "johndoe",
"__v": 0
}DELETE/users/:id
User John Doe was deletedPUT/users/:id- INPUT:
name: Jane Doe
email: [email protected]
password: janedoe
- HTTP Status:
200: OK - JSON data
{
"_id": "59071791b0lkscm2325794",
"name": "Jane Doe",
"email": "[email protected]",
"password": "janedoe",
"__v": 0
}Olajide Bolaji 'Nuel - Software Developer at Andela