https://github.com/jayvirrathi/node-mongodb-rest-api
REST API with Node.js, MongoDB,JWT,PM2
https://github.com/jayvirrathi/node-mongodb-rest-api
jwt jwt-authentication mongodb nodejs openapi pm2 rest-api swagger swagger-documentation
Last synced: 2 months ago
JSON representation
REST API with Node.js, MongoDB,JWT,PM2
- Host: GitHub
- URL: https://github.com/jayvirrathi/node-mongodb-rest-api
- Owner: Jayvirrathi
- Created: 2021-02-07T11:18:56.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-31T10:06:48.000Z (over 4 years ago)
- Last Synced: 2025-02-27T16:53:02.452Z (over 1 year ago)
- Topics: jwt, jwt-authentication, mongodb, nodejs, openapi, pm2, rest-api, swagger, swagger-documentation
- Language: JavaScript
- Homepage:
- Size: 260 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# REST API with Node.js, MongoDB, JWT
> Blog Node.js project
## Build Setup
```bash
# install dependencies
npm install
# serve at http://localhost:4000/
npm start
```
## Prerequisites
- Nodejs
- MongoDB
## Production
```
npm i -g pm2
```
# Build
```
npm run build
```
## dev
```
# serve at http://localhost:4000/
npm run pm2:dev
```
## prod
```
# serve at http://localhost:4000/
npm run pm2:prod
```
**Request:**
### User
```
POST user/register
{
"name": "Elon",
"email": "elon@tesla.com",
"password": "elon@1234",
"role": "author"
}
```
```
POST user/login
{
"email": "elon@tesla.com",
"password": "elon@1234"
}
```
## Authorization
### Post
```
POST posts/
{
"postTitle": "Deno",
"postBody": "New Nodejs Framework",
"genre": "tech"
}
```
```
PUT posts/:id
{
"postTitle": "Deno",
"postBody": "New Nodejs Framework by Nodejs Creator",
"genre": "tech"
}
```
```
GET posts/
GET posts/?page=1&limit=1
GET posts/:id
DELETE posts/:id
```
### Comments
```
POST comments/
{
"postId": "603b77052fbc1c1038573518",
"commentText": "Nice"
}
```
```
PUT comments/:id
{
"postTitle": "Deno",
"postBody": "New Nodejs Framework by Nodejs Creator",
"genre": "tech"
}
```
```
GET comments/
GET comments/:id
DELETE comments/:id
```
### Create Admin User
```
POST admin/register
{
"name": "admin",
"email": "admin@tesla.com",
"password": "admin@1234",
"role": "admin"
}
```
```
POST admin/login
{
"email": "admin@tesla.com",
"password": "admin@1234"
}
```
### Admin Authorization
```
GET admin/users
```