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

express-mongo-spa-boilerplate

v1.3.2

Published

A full fledeged ExpressJS REST API Boilerplate! This repository serves as a foundation for kickstarting your `Express.js + mongodb + SPA` projects. Features organized code structure, comprehensive API documentation, error handling, and more.

Downloads

15

Readme

ExpressJS Starter Boilerplate

A full fledeged ExpressJS REST API Boilerplate! This repository serves as a foundation for kickstarting your Express.js + mongodb + SPA projects. Features organized code structure, comprehensive API documentation, error handling, and more.

installation

git clone https://github.com/AbyerAli/express-mongodb-spa-boilerplate.git
cd expressjs-starter-boilerplate
yarn install
yarn start

or

npm i express-mongo-spa-boilerplate

or

npx express-mongo-spa-boilerplate

Features

  • Dotenv Validation: Environment variables are meticulously validated through the config.js file, ensuring a robust configuration setup.

  • Graceful Error Handling: Easily craft false responses by utilizing the error throwing mechanism. For example:

    throw new Error('Some error XYZ occurred');
    
    
  • dotenv variables are validated at config.js

  • throw error in the API to send false reponse e.g. throw new Error('some error xyz occured')

  • apidoc is generated at /public/apidoc, so remember to update docs before pushing to production with yarn run apidoc

  • yarn run apidoc will generate the docs in /public/apidoc

  • apidocs usage:


/**
    * @api {post} /v1/users/login user login
    * @apiVersion 1.0.0
    * @apiName login user
    * @apiGroup users   
    * @apiPermission authenticated user
    * @apiBody {String} email should follow the email format.
    * @apiBody {String} password should be at least 8 characters long.
    * @apiExample {js} Example usage 1:
    * const user = {
    *   "email": "John Doe",
    *   "password": "xyz"
    * }
    * $http.defaults.headers.common["Authorization"] = token;
    * $http.post(url, data)
    *   .success((res, status) => doSomethingHere())
    *   .error((err, status) => doSomethingHere());
    * @apiExample {js} Example usage 2:
    * const user = {
    *   "email": "John Doe",
    *   "password": "xyz"
    * }
    * axios.defaults.headers.common["Authorization"] = token;
    * axios.post(url, data)
    *  .then((res, status) => doSomethingHere())
    * .catch((err, status) => doSomethingHere());
    *
    * @apiSuccess (Success 200) {String} token token to access the api
    * @apiSuccessExample {json} Success response:
    *     HTTPS 200 OK
    *     {
    *      "status": true,
    *      "message": "Task saved successfully!",
    *       "data": {
    *           token: "xyz"
    *      },
    *    }
    * @apiUse UnauthorizedError
*/
router.post('/login', validateUser, userController.userlogin);
  • public contains any static files that will be served to the client.
  • routes contains all the routes for the application.
  • controllers contains all the controllers for the application.
  • models contains all the models, schemas for the application.
  • services contains all the services for the application like S3, Multer, Mailer etc.
  • helpers contains all the utility functions for the application.
  • api data response format:
{
    "status": true,
    "message": "Task saved successfully!",
    "data": {
        "token": "xyz"
    },
}
  • api error response format:
{
    "status": false,
    "message": "error message",
    "error": {
        "some error": "xyz"
    },
}
  • from every route either success or error response will be used provided in helper/methods.js, in case of error, error middleware will be used as all the errors are handled in the error middleware (centralized).
  • Validation is done using express-validator and joi, before any route is hit, validation is done and if any error is found, express-vaidator is used to pluck out the error and send it to the user.
  • logs are generated and stored in logs folder via use of logs middleware used in server.js
  • any environment variables are stored in .env file and are validated and exported at config.js
  • config.js contains all the configuration for the application.
  • server.js is the entry point for the application.