Skip to content

gpavankv/users-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTful API using Node.js, Express, MongoDB.

A RESTful API created using Node.js, Express, MongoDB along with bcryptjs and jsonwebtoken to implement security features for hashing and authenticaion.

Getting Started

Download the zip file or clone using git clone https://github.com/gpavankv/users-api.git.

Prerequisites

Just run npm install in your command prompt or terminal

$user npm install

or

folder\AnotherFolder> npm install

Run App

Use commands npm run start or nodemon to run the app. For now there are only three routes.

  1. Basic test route make a get request to http://localhost:3050/api/test, the server will return a message.
{
    "message": "Test Successful!"
}
  1. A POST request to http://localhost:3050/api/createuser with
{
    "firstName": "John",
    "lastName": "Doe",
    "email":"[email protected]",
    "password": "johndoe123"
}

as body of the request, the server will return a message

{
    "message": "User created"
}

and the mongodb users collection should have some thing like this

{
    "_id" : ObjectId("5a53096475c0fa5c78858427"),
    "firstName" : "John",
    "lastName" : "Doe",
    "email" : "[email protected]",
    "password" : "$2a$16$fRSD9aXXSzhc9dQl5JUIB.RG8aV1bIk6sG8HLwYTCdjHS.scBq16i",
    "__v" : 0
}
  1. A POST request to http://localhost:3050/api/verifyuser with
{
    "email":"[email protected]",
    "password": "johndoe123"
}

as body of the request, the server will return a message

{
    "message": "John Doe",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7Il9pZCI6IjVhNTNkMWVkNmNkM2ZmMjBmMDM5MjM0MSIsImZpcnN0TmFtZSI6IkpvaG4iLCJsYXN0TmFtZSI6IkRvZSIsImVtYWlsIjoiam9obkBkb2UuY29tIiwicGFzc3dvcmQiOiIkMmEkMTYkOG85LlY1aC9iQmRoUS9IclhFNXhLdVAwcjk4MzJyRlBpU01oY2VWUE9EZFRzTmVGenE5LlciLCJfX3YiOjB9LCJpYXQiOjE1MTU0NDI3MDV9.G3odkBj9sCxftx2QFKLym3m_pTSQ7ejVcp6uE__Zx7c"
}

and from here on you can persist this token and use it for subsequent requests.

Running the tests

npm run test

Authors

License

This project is licensed under the MIT License.

Acknowledgments

About

Users RESTful API for Angular Employee App

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published