Toflex / staticpages-microapi

Backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static Pages API

To Contribute...

  1. Create a personal fork of this repo on your Github.

  2. Clone the fork on your local machine (pc) . using "git clone url of the repo." Once you have cloned your remote on Github is called origin.

  3. On your local machine (pc) inside the cloned project, add the origin repository as a remote called upstream. i.e git remote add upstream url of the repo.

  4. Create a new branch to work on. Branch from the master branch. It is recommended that you make a new branch for every new feature you work on and work from there. You can use "git checkout -b name of new brach" shorthand to create a new brach and switch to it .

  5. Push your branch to your fork Github, i.e the remote origin.

  6. From your fork open a pull request in the correct branch. Target the project's master branch.

  7. Be sure to always pull upstream changes into your local repository to keep updates of the main repo.

"git pull upstream branch_name" which is the main branch (master).

These are the set of instructions from Mark.

Try and always: 8. Comment your codes properly.

  1. Follow the code style of the project including indentation.

GOOD LUCK...

Getting started After Cloninig

This is a basic API skeleton written in JavaScript ES2015. Very useful to building a RESTful web APIs for your front-end platforms like Android, iOS or JavaScript frameworks (Angular, Reactjs, etc).

This project will run on NodeJs using MongoDB as database. I had tried to maintain the code structure easy as any beginner can also adopt the flow and start building an API. Project is open for suggestions, Bug reports and pull requests.

Features

  • Basic Authentication (Register/Login with hashed password)
  • Email helper ready just import and use.
  • JWT Tokens, make requests with a token after login with Authorization header with value Bearer yourToken where yourToken will be returned in Login response.
  • Pre-defined response structures with proper status codes.
  • Included CORS.
  • Validations added.
  • Included API collection for Postman.
  • Light-weight project.
  • Test cases with Mocha and Chai.
  • Code coverage with Istanbuljs (nyc).
  • Included CI (Continuous Integration) with Travis CI.
  • Linting with Eslint.

Software Requirements

  • Node.js 8+
  • MongoDB 4+

Getting started with the Server

Install npm dependencies after installing (Git or manual download)

npm install

Setting up environments

  1. You will find a file named .env.example on root directory of project.
  2. Create a new file by copying and pasting the file and then renaming it to just .env
    cp .env.example .env
  3. The file .env is already ignored, so you never commit your credentials.
  4. Change the values of the file to your environment. Helpful comments added to .env.example file to understand the constants.

Project structure

.
├── app.js
├── package.json
├── bin
│   └── www
├── controllers
├── models
├── routes
│   ├── api.js
├── middlewares
│   ├── jwt.js
├── helpers
│   ├── apiResponse.js
├── test
│   ├── testConfig.js
│   ├── auth.js
│
└── public
    ├── index.html
    └── stylesheets
        └── style.css

How to run

Running API server locally

npm run dev

You will know server is running by checking the output of the command npm run dev

Connected to mongodb:YOUR_DB_CONNECTION_STRING
App is running ...

Press CTRL + C to stop the process.

Note: YOUR_DB_CONNECTION_STRING will be your MongoDB connection string.

Creating new models

If you need to add more models to the project just create a new file in /models/ and use them in the controllers.

Creating new routes

If you need to add more routes to the project just create a new file in /routes/ and add it in /routes/api.js it will be loaded dynamically.

Creating new controllers

If you need to add more controllers to the project just create a new file in /controllers/ and use them in the routes.

Tests

Running Test Cases

npm test

You can set custom command for test at package.json file inside scripts property. You can also change timeout for each assertion with --timeout parameter of mocha command.

Creating new tests

If you need to add more test cases to the project just create a new file in /test/ and run the command.

ESLint

Running Eslint

npm run lint

You can set custom rules for eslint in .eslintrc.json file, Added at project root.

About

Backend

License:MIT License


Languages

Language:JavaScript 95.4%Language:HTML 3.0%Language:CSS 1.7%