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

nodeexpressfilestructure

v1.0.8

Published

The aim of this package is to create a folder structure for your node-express applications following the MVC architecture. The structural choices made for this package have been based on my experience developing node-express applications and are open t

Downloads

1

Readme

Introduction

The aim of this package is to create a folder structure for your node-express applications following the MVC architecture. The structural choices made for this package have been based on my experience developing node-express applications and are open to reviews and alterations. Below represent some actions to be carried out for each package with suggestions made for each folder and file.

Actions

  • Initialize git with "git init" to add git to project.
  • Install express with "npm install express".
  • Create a .gitignore file.
  • Create a .env file and check this into .gitignore.

Configurations

package.json

  • Install the nodemon package as a development dependency using "npm install nodemon --save-dev"

  • Edit the following fields to suit your needs

        "name": ,
        "version": ,
        "description": ,
        "keywords": [],
        "author": {
          "name": ,
          "email": 
        },
        "license":
      
  • Add more fields as required to the package.json file

  • Add more scripts as required.

.env

  • Set the NODE_ENV via the command line using either the SET or EXPORT keyword as defined below

      SET NODE_ENV=production (for production environment)
      EXPORT NODE_ENV=developemnt (for development environment)`
  • Install the dotenv package using "npm install dotenv"

  • In the .env file created, set the PORT number, local and online database connection string and other environment variables using the format below

      PORT=5000
      DB_LOCAL=LOCAL_CONNECTION_STRING
      DB_ONLINE=ONLINE_CONNECTION_STRING
      EXAMPLE_ENVIRONMENT_VARIABLE=EXAMPLE_ENVIRONMENT_VALUE

readme.MD

  • Edit file to describe your project and highlight specific actions to be carried out in running your project.

server.js

  • Main entry into your app. The server exported here can be used during testing.

app.js

  • Add other startup files required for your application by requiring the files containing them from the startup folder.

Startup

db.js

  • npm install winston
  • npm install mongoose
  • Set DB connection string in the .env file

logging.js

  • npm install winston-mongodb (if you want winston to write log Files to mongodb database. Could cause errors when used during testing)
  • npm install express-async-errors (used for handling errors and logging these errors)

routes.js

  • register routes and middleware here.

index.js

  • Add other startup files required for your application by requiring the files containing them from the startup folder. Remember here that the order of files being required is very important e.g logging files should come above every other file that requires the logging functionality.

config.js

  • Add Code to throw Error when specific environmental variables needed for app startup are not provided e.g PORT number

  • Add other startup files that work as middleware needed in the request response cycle e.g

      validation.js (add middleware required for data validation 
      e.g joi-objectid),
        
      views.js (add middleware required for view engines e.g middleware for 
      handlebars view engine),
        
      session.js (add middleware for session management on the server),
        
      flashMessaging.js (add middleware for flash messaging e.g connect-flash),
        
      production.js (add production based middleware e.g helmet) e.t.c

routes

  • Add routes as necessary. Group routes based on the API end point

middlewares

  • Add middleware necessary for the project e.g authentication.js, maintenance503.js e.t.c. Remember to call next() to allow for continuation of the request-response processing pipeline
  • globalErrorHandler.js catches any error in the request-processing pipeline and uses winston to log these errors.

models

  • Install mongoose with "npm install mongoose".
  • Place all utility functions relating to all models in utils.js.
  • Create a folder for each collection in the database and describe its model in this folder.
  • Add methods on the model schema to the methods folder.
  • Add statics on the model schema to the statics folder.
  • Add pre actions on the model schema to the pre folder.
  • Add post actions on the model schema to the post folder.
  • Add other methods closely tied to the model schema to the utils folder.

views

  • Add view engine code here and structure the view engine folder as recommended for the view engine chosen. View engines could be pug, jade, handlebars, e.t.c

controllers

  • Add controller folder for each major API endpoints necessary for the project.
  • Add controller files containing controller logic for the CRUD action necessary for that particular endPoint
  • Create an index.js file for each controller folder to export all the controllers from one file.

public

  • Add css based code to css folder and structure the folder according to your css needs.
  • Add project images to images folder and structure the folder according to your project images structure.
  • Add client-side javascript code here and structure the folder according to your client-side javascript needs.
  • Add html pages to the root of this folder e.g index.html, about.html, e.t.c . Note to remove the index.html file when using a view engine (e.g handlebars) as it will override the index page for your view engine.

tests

/__mocks__

  • Mock third-party API calls here i.e API calls for third-party services e.g sending mails, payment services.

/fixtures

  • Add code that would usually come up in your beforeEach and afterEach calls. Export this code so that they can be available for multiple test suites e.g code to setup and clean a database.
  • Add other files that might be needed for testing API endpoints e.g photo.jpg needed to test file uploads.

/integration

  • Add integration tests here and group these tests according to the file structure used in the project e.g middleware folder for integration tests for files in the project's middleware folder.

/unit

  • Add unit tests here and group these tests according to the file structure used in the project e.g controller folder for unit tests for files in the project's controller folder.

Add other files and folders as required for your project.