Skip to content

marroq/API-NodeJS-MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API-NodeJS-MongoDB

Installation

You have to install the following dependencies to run this API.

Install express

npm install -S express

Install mongoose to work with MongoDB

npm i -S mongoose

Install dotenv to read you .env file

npm install dotenv --save

Install bcrypt, jsonwebtoekn and express-jwt for authentication and authorization

npm i -S bcrypt jsonwebtoken express-jwt

The applition is running in port 3000 with the following methods:

Environment Variables

Create a .env file and add the following variables

  • MONGO_URI: connection string to MongoDB
  • SECRET: secret to sign and validate jwt

Authentication

  • Register a new user.

Method: GET

http://localhost:3000/register
  • Login with an existing user.

Method: GET

http://localhost:3000/login

Users CRUD

These methods need a JsonWebToken generated by login method and send it with the next Header.

{
    "Authorization": Bearer {jwt}
}
  • List all users

Method: GET

http://localhost:3000/users
  • Get a specific user

Method: GET

http://localhost:3000/users/{user_id}
  • Create new user

Method: POST

http://localhost:3000/users

Body

{
    "name": "String",
    "lastName": "String"
}
  • Update user

Method: PUT

http://localhost:3000/users/{user_id}

Body

{
    "name": "String",
    "lastName": "String"
}
  • Delete user

Method: DELETE

http://localhost:3000/users/{user_id}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published