An example REST API project using NodeJS(ExpressJS) and MongoDB.
- Local Authentication using Email and Password (Login and Register)
- REST API: Create, update, get, list, delete todo
Description | URL | METHOD | PAYLOAD | EXAMPLES |
---|---|---|---|---|
Get list todos | /draft?page={number} | GET | GET /draft?page=1 | |
Create a new todo | /draft | POST | {title: String} | POST /draft data: {title: "hello"} |
Delete a todo | /draft/:id | DELETE | DELETE /draft/123 | |
Un/Complete a todo | /draft/:id/toggle | POST | POST /draft/123/toggle | |
Update a todo | /draft/:id | PUT | {title: String} | PUT /draft data: {title: "update"} |
Register | /register | POST | {email: String, | |
password: String, | ||||
name: String} | ||||
Login | /login | POST | {email: String, | |
password: String} |
# Clone this project to your local.
git clone https://github.com/UETCodeCamp/todo-api.git my-project
# Change directory
cd my-project
# Install package dependencies
npm install || yarn
# Start your app
npm start
Note: I highly recommend installing Nodemon. It watches for any changes in your node.js app and automatically restarts the server. Once installed, instead of node app.js use nodemon app.js. It will save you a lot of time in the long run, because you won't need to manually restart the server each time you make a small change in code. To install, run:
sudo npm install -g nodemon
You can add file {environment}.env
to change configuration (with environment = NODE_ENV
).
Example: NODE_ENV=development => file name is: development.env
UCC_SECRET_KEY=secret_key
UUC_PORT_APP=1234
UUC_MONGODB_URI=mongodb://localhost:27017/todo_new_app
- Collection link: https://www.getpostman.com/collections/8792c668140a00124025