# backend-base-node

> This repository will serve as a boiler plate for new backend APIs to be developed in NodeJs and MongoDB. All the necessary basic modules required to start a project will be setup along with different environment compatibility to reduce setup time.

Latest version **1.0.0** (published 2018-07-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install backend-base-node
pnpm add backend-base-node
yarn add backend-base-node
bun add backend-base-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-07-26 |
| First published | 2018-07-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 33 |
| Unpacked size | 33.8 KB |
| Known vulnerabilities | 0 (+17 in 7 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Nikhil Gurnani |
| Maintainers | nikhilgurnani |
| Keywords | backend, base, nodejs, mongodb, mongo, boilerplate, basic, setup |

## Links

- npm: https://www.npmjs.com/package/backend-base-node
- Repository: https://github.com/Grappus/backend-base-node
- Homepage: https://github.com/Grappus/backend-base-node#readme
- Issues: https://github.com/Grappus/backend-base-node/issues
- npm.io page: https://npm.io/package/backend-base-node

## Dependencies (33)

- [pm2](https://npm.io/package/pm2.md) ^2.9.1
- [chai](https://npm.io/package/chai.md) ^4.1.2
- [async](https://npm.io/package/async.md) ^2.6.0
- [mocha](https://npm.io/package/mocha.md) ^4.0.1
- [redis](https://npm.io/package/redis.md) ^2.8.0
- [uuid4](https://npm.io/package/uuid4.md) ^1.0.0
- [assert](https://npm.io/package/assert.md) ^1.4.1
- [cities](https://npm.io/package/cities.md) ^1.1.2
- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [dotenv](https://npm.io/package/dotenv.md) ^4.0.0
- [eslint](https://npm.io/package/eslint.md) ^4.13.1
- [helmet](https://npm.io/package/helmet.md) ^3.9.0
- [jshint](https://npm.io/package/jshint.md) ^2.9.5
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.171.0
- [cluster](https://npm.io/package/cluster.md) ^0.7.7
- [express](https://npm.io/package/express.md) ^4.16.2
- [winston](https://npm.io/package/winston.md) ^2.4.0
- [fast-csv](https://npm.io/package/fast-csv.md) ^2.4.1
- [json2csv](https://npm.io/package/json2csv.md) ^3.11.5
- [mongoose](https://npm.io/package/mongoose.md) ^4.13.7
- [node-ses](https://npm.io/package/node-ses.md) ^2.1.0
- [chai-http](https://npm.io/package/chai-http.md) ^4.0.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.2
- [country-data](https://npm.io/package/country-data.md) 0.0.31
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.1.0
- [string-format](https://npm.io/package/string-format.md) ^0.5.0
- [all-the-cities](https://npm.io/package/all-the-cities.md) ^2.0.0
- [firebase-admin](https://npm.io/package/firebase-admin.md) ^5.12.1
- [countrystatesjs](https://npm.io/package/countrystatesjs.md) 0.0.12
- [csv-write-stream](https://npm.io/package/csv-write-stream.md) ^2.0.0
- [express-fileupload](https://npm.io/package/express-fileupload.md) ^0.3.0
- [winston-loggly-bulk](https://npm.io/package/winston-loggly-bulk.md) ^2.0.1
- [eslint-config-google](https://npm.io/package/eslint-config-google.md) ^0.9.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-07-26

## README

> **Authors:**

> - nikhil@grappus.com (**Nikhil Gurnani**)

# backend-base-node
This repository contains a basic NodeJs initialised project with Mongo DB and ExpressJs to be used as a boiler plate for the new backend API development. This repository will be actively maintained by @nikhilgurnani. 


###Coding Conventions
----------
 [1]. Use camelCase
 
 [2]. Every module name in package must start with package name
  > ex - While writing a module for *User* in package *models* then module file name must be **modelsUser** and if the package name is *controller* then module file name must be **controllerUser**
  
[3]. Run ```npm run test``` to check test case status.  

[4]. Declare and use constants as much as possible.

[5]. Create atomic functions for each task and call functions to do your tasks.

[6]. Ensure you write test cases for every API endpoint you create.

###HTTP Status Code convention
----------

Status          | Condition
----------------| ---
200             | request is OK and fulfilled, Get and Put requests mostly
201             | new record created, post request mostly
204             | no content, delete calls mostly
206, 302        | api change and redirect
400             | Bad Request. The data is not valid in request. We prefer 400 over 206 (partial content)
401             | If auth_token is invalid. Once API return 401 ask client apps to logout and re-login
403             | Invalid auth. Use auth header, to protect resources. Also used for Invalid Permissions in                   some cases


### Project Setup
----------
[1]. First create "logs" directory in src folder

[2].  Then create .env file in parent directory and copy keys from sample.env into it and change values appropriately

[3]. Ensure you have MongoDB installed and a service running for the DB.

[3]. Run "npm install" to install packages and dependencies listed in the package.json

[4]. After that just run "npm run start".

> **Tech Stack:** We are using NodeJs with ExpressJs framework, MongoDB as primary database, Redis for caching and AWS as main cloud service. Mocha and chai with chai-http for TDD

### API Structure
----------
> **Note:** Return 401 in case invalid authToken and ask application developer to clean all data from local storage of that user

[1]. Error response structure
```
{
      **error**: "It could be string or object or list or object. Frontend need not to worry about this.",
      **message**: "It must be a string. Frontend will show this to user.",
      **errorCode**: "Our unique codes. Depends on user input and db response. These must be set in controller/controllerConstants.js"
}
```
[2]. Success result, a list, we are using offset to paginate result
```
{
      result: [
        {
          This will be object here
        },
        {
          ...
        }
      ],
      count: "This will be an integer",
      next: boolean # Will tell about whether to make next call or not?
      nextOffset: Integer # Will tell about next offset value.
}
```
[3]. Success result, Single object, a valid object
```
{
  result: {
    Object will come here.
  }
}
```
[4]. Success result, no data to return
```
{
  success: true
}
### Project Structure
----------
  we are using [dotenv][1] package.
  Check sample.env to refer sample env file.

> For services, we use:
> - AWS SES (Simple Email Service) ------> Emails
> - FCM (Firebase Cloud Messaging) ------> Push Notifications
> - Cloud File Storage (AWS BOTO) -------> File Storage

In src folder you will get 7 main folders, named:

**cache**
:   contains cache-models and object

**controllers**
: contains all functions related to business logic. All module
      name must start with *controller*
      
**middleware**
: contains middleware modules. All module name must start with
      *middleware*
      
**models**
: contains all functions and related to DB and also the DB related
      methods. All module name must start with *model*

**routes**
: contains routes related modules and bind endpoints to
      controllers. All module name must start with *route*

**scripts**
: ontain random scripts, non JS files, use for random tasks

**utils**
: contains common util modules. All module name must start with
      *util*

> **Note:**
> - If a project requires usage of Notifications, you can find a (**utils > utilNotifications.js**), that contains an independent function that can send Push, Email or SMS Notification by accepting some paramters. 
> - In test folder you will get all the test cases file. Ensure you write test cases for each and every API endpoint
> - Apart from that there is a main file called "server.js". It is the entry point of this project. Please first read that file


  [1]: https://github.com/motdotla/dotenv

---
_Source: https://npm.io/package/backend-base-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
