Giter Club home page Giter Club logo

dekhle-backend's Introduction

Nodejs boilerplate REST API

This repo can be cloned/forked and used as a boilerplate for a node REST API

I built this repo to learn how to make a rest api and server. It was created by following this tutorial, and has been expanded on to service the needs of a boilerplate project. I've also used inspiration from this awesome dev!

The different things you can do with this server:

  • Controllers - deals with database read/write operations and logic.
  • Models - define schemas of objects in collections the database.
  • Routes - defines the API routing for controller functions.
  • Middlewares - helper files, utils and methods. Basically anything that isn't done by a controller.

Installing & config

  1. Clone repo and run npm i to install all packages

  2. In the server.js file, you can modify the database location and name on line 22

  3. Run MongoDB locally with brew services start mongodb-community

Running the project

  1. Add a .env flie to the root directory when first cloning this project for storing environment variables

  2. Add a JWT_SECRET to the .env file

  3. Start the server with nodemon: npm start. Currently the default port for the server is 5000 and this can be set in the .env. This is to prevent clashes when running the server and clients in dev locally.

  4. Restart running server by typing: rs

Available Scripts

  • start - starts the server
  • reset - deletes the node_modules
  • reinstall - deletes and then reinstalls the node_modules
  • test - runs all unit tests
  • test:watch - watches for unit tests that have changed and reruns the test suite

Current Routes

Auth Routes

/api/v1/auth/login-user

  POST:
  {
    "email": "",
    "password": "" (at least 6 characters long and contain a lowercase letter, an uppercase letter, a numeric digit and a special character.)
  }

/api/v1/auth/create-new-user

  POST:
  {
    "firstName": "", (firstName is optional)
    "lastName": "", (lastName is optional)
    "email": "",
    "password": "" (at least 6 characters long and contain a lowercase letter, an uppercase letter, a numeric digit and a special character.)
    "password2": ""
    "acceptedTerms": Boolean
  }

/api/v1/auth/verification/verify-account/:uniqueId/:secretCode

This route is activated when a user clicks the link in an email sent to then when creating a new account.

/api/v1/auth/password-reset/get-code

Allows a user to get a password reset code emailed to them.

  POST:
  {
    "email": "",
    "password": "",
    "password2": "",
    "code": "" (this will have been emailed to the user)
  }

`/api/v1/auth/password-reset/verify-code

Allows a user to get a password reset code emailed to them.

  POST:
  {
    "email": ""
  }

/api/v1/auth/delete-account

Allows a user to delete their account.

  POST:
  {
    "password": "",
    "uniqueId": ""
  }

/api/v1/auth/check-token-valid-external/:token

  GET
  External route to check if a token is valid

dekhle-backend's People

Contributors

linkstatic12 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.