https://github.com/pauloportugal/nodejs-task-manager
A Node.js REST api with Mongoose
https://github.com/pauloportugal/nodejs-task-manager
expressjs mongodb mongoose nodejs rest-api restful-api
Last synced: 4 months ago
JSON representation
A Node.js REST api with Mongoose
- Host: GitHub
- URL: https://github.com/pauloportugal/nodejs-task-manager
- Owner: PauloPortugal
- License: gpl-2.0
- Created: 2020-02-16T00:13:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-22T19:28:01.000Z (over 3 years ago)
- Last Synced: 2025-07-26T06:42:09.809Z (11 months ago)
- Topics: expressjs, mongodb, mongoose, nodejs, rest-api, restful-api
- Language: JavaScript
- Size: 256 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A Node.js task manager REST API with Mongoose
A Node.js REST API with [Mongoose](https://mongoosejs.com/docs/) and [Express.js](http://expressjs.com/)
This is part of Andrew Mead's (mead.io) "The Complete Node.js Developer Course".
## Goal
Create a task manager via a REST API.
Additionaly uses:
* [async/await](https://javascript.info/async-await) to handle asyncronous operations
* [bcryptjs](https://www.npmjs.com/package/bcryptjs) to hash passwords
* [JWT](https://www.npmjs.com/package/jsonwebtoken) for representing claims securely between the client and the API
* [Express.js middleware](https://expressjs.com/en/guide/using-middleware.html) to validate user sessions
## CURL examples
Below are a few `curl` commands to exercise the REST API user resources
```
# create a new user
curl -X POST -H "Content-Type: application/json" -i "localhost:3000/users" -d '{"name":"James", "password":"somePaw98", "email":"test@test.com", "age":38}'
# login
curl -X POST -H "Content-Type: application/json" -i "localhost:3000/users/login" -d '{"password":"somePaw98", "email":"test@test.com"}'
# logout
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/users/logout"
# logout and delete all sessions
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/users/logoutAll"
# return user profile
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/users/me"
# return all users
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/users"
# return one user
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/users/:id"
# update the details of an user
curl -X PATCH -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/users/me" -d '{"age":50}'
# delete one user
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/users/me"
```
Below are a few `curl` commands to exercise the REST API task resources
```
# create a new task
curl -i -X POST -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/tasks" -d '{"description":"Buy some groceries"}'
# return all tasks
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/tasks"
# return one task
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/tasks/:id"
# update the details of a task
curl -X PATCH -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/tasks/:id" -d '{"description":"Buy four apples"}'
# delete one task
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN_ID" -i "localhost:3000/tasks/:id"
```