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

bootstrap-express-app

v1.2.0

Published

Generate a boilerplate for a NodeJs Express and MongoDB CRUD application with best practices.

Downloads

16

Readme

ExpressJs-Best-Practices-Boilerplate

Introduction

ExpressJs-Best-Practices-Boilerplate is a boilerplate for building ExpressJs applications with basic user CRUD and login/logout functionality. It uses the Express framework and MongoDB for database storage.

Prerequisites

  • Node.js version v20.10.0
  • Git
  • MongoDB
  • Postman

Installation

  1. Initialization command:
    npx bootstrap-express-app my-app
    cd my-app
  2. Start Project:
    npm start

Documentation

Postman Collection:

  • Find the Postman collection in the "postman collection doc" folder.
  • Import Postman collection JSON file from postman

Swagger Documentation:

  1. Create command:

    • After adding inline documentation comments and schemas to newly created or modified endpoint routes, run the following command to generate the Swagger documentation JSON file.
      npm run create-swagger-doc
    • For Inline documentation comments and schemas click here
  2. Usage:

    • For Swagger documentation, first, start the server and navigate to the '/api-docs' route. Ex. http://localhost:3000/api-docs

Usage

Development Environment:

To start the server in the local environment

npm run dev

Production Environment:

To start the server in the production environment

npm run prod

Monitoring Logs:

To watch logs in the production environment

pm2 logs

Reloading Instances:

To reload all instances of the production environment

npm run prod-reload

Stopping Instances:

To stop all instances of the production environment

npm run prod-stop

Authentication Flow

  • When a user logs in with valid credentials, the server sends both an access token and a refresh token as cookies.

  • All protected routes require token validation for access.

  • If a protected route returns a status code of 401 (Unauthorized), the client needs to send a request to the '/auth/refresh_token' endpoint.

  • The '/auth/refresh_token' endpoint validates the refresh token, and if valid, generates a new pair of access and refresh tokens.

  • If the refresh token is not valid, an error response with a status code of 401 is sent, requiring the user to log in again.

Git Best Practices

Commit Standards

  • Atomic Commits: Each commit should represent a single logical change. Avoid combining unrelated changes in a single commit.

  • Meaningful Commit Messages: Write clear and concise commit messages that describe the purpose of the change. Follow the imperative mood (e.g., "Add feature" instead of "Added feature").

  • Commit Types: Commit type must be following one:

    • feat: A new feature
    • fix: A bug fix
    • style: Changes that doesn't affect meaning of code(semi-colon, indentation, etc)
    • perf: Improve performance
    • refactor: Refactor code
    • test: Add missing test cases
    • docs: Documentation only change
    • chore: Change in auxiliary tools like documentation or seed change
  • Reference Issues: If your commit is related to a specific issue or task, reference it in the commit message. For example, fix: #123 or feat: #456. Here #123 or #456 are ticket Id.

Branch Name Standards

  • Use Hyphens for Branch Names: Use hyphens to separate words in branch names. For example, use feature-branch instead of feature_branch or featureBranch.

  • Prefix Branch Names: Prefix branch names with a category or type. For example:

    • feature/ for feature branches
    • fix/ for fix branches

Thank you 😊