npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

create-benm-app

v0.1.3

Published

Boilerplate for REST API with Node.js, ExpressJS, and MongoDB

Downloads

31

Readme

BENM | Boilerplate for REST API

Codacy Badge Codacy Badge Travis (.com)

A ready-to-use boilerplate for REST API Development with Node.js, Express, and MongoDB

Getting started

This is a basic API skeleton written in JavaScript ES2015. Very useful for building 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)
  • Account confirmation with 4 (Changeable) digit OTP.
  • 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.
  • Product && User example with CRUD operations.
  • Validations added.
  • Included API collection for Postman.
  • Light-weight project.
  • Postman Collection Link
  • 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 12+ (Recommended 16+)
  • npm 6+ (Recommended 8+)
  • MongoDB 3.6+ (Recommended 4+)

How to install

Using npm or npx (recommended)

  1. create a BENM app with the npm command. Change "myproject" to your project name.
 npx  create-benm-app myproject

or

 npm init benm-app myproject

Using Git

  1. Clone the project from github. Change "myproject" to your project name.
git clone https://github.com/umagol/NodeJs-ExpressJS-MongoDB-Boilerplate.git ./myproject

Using manual download ZIP

  1. Download the repository
  2. Uncompress to your desired directory

Note: Remove all unwanted files and folders.

Install npm dependencies after installing (Git or manual download)

cd myproject
npm install

Setting up environments (Git or manual download)

  1. You will find a file named .env.example on the project's root directory.
  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 were added to the .env.example file to understand the constants.

Project structure

.
├── src
│    ├── bin
│    │   └── www
│    ├── controllers
│    │   ├── AuthController.js
│    │   └── ProductController.js
│    ├── constants
│    │   ├── mailTemplate.js
│    ├── models
│    │   ├── ProductModel.js
│    │   └── UserModel.js
│    ├── routes
│    │   ├── api.js
│    │   ├── auth.js
│    │   ├── privateRouter.js
│    │   ├── publicRouter.js
│    │   └── index.js
│    ├── middlewares
│    │   ├── jwt.js
│    ├── helpers
│    │   ├── apiResponse.js
│    │   └── mailer.js
│    ├── service
│    │   ├── auth.service.js
│    └── utility
│    │   └── utility.js
│    └── app.js
│── public
│    └── index.html
│── test
│    ├── auth.js
│    └── testConfig.js
└── package.json

How to run 🤔

Running API server locally

npm run dev

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

DataBase connected successfully...
🚀App is running ... 

Press CTRL + C to stop the process.

Note: Update your MongoDB connection string in .env file.

Run application using docker

Run docker using compose file (recommended)

npm run start:docker

Build docker image

npm run build:docker

Run docker image container

npm run start:docker-image

Note: into the docker-compose.yml file update your local configuration. and install docker in your system.

Creating new controllers

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

Creating new models

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

Creating new routes

If you need to add more routes to the project there are three types of routes:

  1. private route

    • The route that requires authentication

    Note: we have created auth middleware for checking the user token Bearer token require.

  2. public route

    • the route that accesses publicly
  3. auth route

    • route related to authentication ( for example login, register, forgot password, etc )

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

Tests

Running Test Cases

npm test

You can set a custom command for a test at the package.json file inside the 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 the .eslintrc.json file, Added at the project root.

Bugs or improvements

Every project needs improvements, Feel free to report any bugs or improvements. Pull requests are always welcome.

License

This project is open-sourced software licensed under the MIT License. See the LICENSE file for more information.