Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

NodeJs/Typescript API Boilerplate

Open Source Love GitHub issues GitHub stars GitHub forks GitHub license

For Enterprise

Running the app

NOTE: These instructions require MongoDB and Node.js to be installed on your environment.

Clone the Repository

git clone https://github.com/ofuochi/node-typescript-boilerplate.git
cd node-typescript-boilerplate

Create Your Branch

git checkout -b <INSERT-BRANCH-NAME>

Install Dependencies

npm install

Copy Files

Sample env File into a .env File

cp env.sample .env

Run the App

npm run start

Open

http://localhost:3000/api/v1/tenants

Run Tests

Run test once

npm run test

Or re-run test on every file change (watch mode)

npm run test-watch

REST Services

The application exposes a few REST endpoints which requires you to pass x-tenant-id header. First call the tenant endpoint /api/v1/tenant to get all the available tenants. Use any of the tenant IDs as the value for x-tenant-id

  • HTTP GET /api/v1/tenants
  • HTTP GET /api/v1/tenants/:query
  • HTTP GET /api/v1/secured (Requires a valid x-auth-token header)

You can use the following code snippet to call the secured endpoint:

fetch("http://localhost:3000/api/v1/secure", {
    method: "GET",
    headers: {
        "Content-Type": "application/json",
        "x-tenant-id": "TENANT_ID",
        "x-auth-token": "SOME_VALID_CREDENTIAL"
    }
})
    .then(r => {
        if (r.status === 200) {
            r.json().then(j => console.log(j));
        } else {
            console.log("ERROR", r.status);
        }
    })
    .catch(e => console.log(e));

You can use the following code snippet to call the secured endpoint with an invalid x-auth-token header:

fetch("http://localhost:3000/api/v1/secure", {
    method: "GET",
    headers: {
        "Content-Type": "application/json",
        "x-tenant-id": "TENANT_ID",
        "x-auth-token": "SOME_WRONG_CREDENTIAL"
    }
})
    .then(r => {
        if (r.status === 200) {
            r.json().then(j => console.log(j));
        } else {
            console.log("ERROR", r.status);
        }
    })
    .catch(e => console.log(e));