Skip to content

FranciscoMarmolejo/Notes-REST-Api

 
 

Repository files navigation

NOTES API

A simple REST Api in Node js :)

Sorry for my bad English :(

Content
  1. About
  2. Setup
  3. Usage

About

Simple REST Api for creating notes with authentication. This project was built with:

Setup

Requirements

  • Node v14

  • Express v4.17

  • Mongo v4.4

  • Redis v6

  • Docker v20.10

For the tests

  • Jest v26.6

  • Ajv v6.12

  • Redis-mock v0.55

  • Supertest v6.0

Installation

Install npm before these steps if you don't have it.

  1. Clone the repo.
git clone https://github.com/JavierNafa/Notes-REST-Api.git
  1. Run this command in terminal inside folder project.

npm i

  1. Create a file called .env in the root folder.
Env name Description
MONGO_HOST The host of mongoDb. If you are going to run this without docker set the remote host or use the default localhost.
MONGO_PORT The mongoDb port. Default 27017.
MONGO_DB_NAME The name of the mongo database. Default notes .
REDIS_DB_INDEX The redis database number. Default 0.
REDIS_HOST The host of redis. If you are going to run this without docker set the remote host or use the default localhost.
REDIS_PORT The redis port. Default 6379.
REDIS_EXPIRATION The expiration time of each key in seconds. Default 60.
PORT The REST Api port . Default 8000.
TOKEN_KEY JWT secret key. Example supersecret123.
TOKEN_EXPIRATION_TIME The expiration time of the jwt. Default 1h.
EMAIL_USER The email to send a test mail.
EMAIL_PASSWORD Email password.
EMAIL_SERVICE The service supported by nodemailer

Usage

Without docker

  1. Create the .env file with the above variables.

  2. Make sure mongodb and redis are running first. After that, run npm start

in the root folder.

  1. Enter the following url in your favorite browser http://localhost:PORT/doc to see all routes.

  2. Create a user /user.

  3. Log in /login.

  4. Use the token to authorize you. Example Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

  5. You can now create, read, update and delete notes.

With docker

  1. Set the .env file only with PORT , TOKEN_KEY and the EMAIL variables if you want to use the default values.

  2. Run docker-compose up in the root folder.

  3. Follow steps 3-7 of the section without docker.

Tests

The tests were maded with Jest.

  1. First check that the connection with redis and mongodb is ok.

  2. Run npm test in the root folder.

Thanks for reading this.

About

Simple REST Api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 58.9%
  • HTML 36.5%
  • CSS 4.4%
  • Dockerfile 0.2%