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

ewsb-template

v1.0.2

Published

Basic boilerplate for Express socket.io

Downloads

1

Readme

EXPRESS-SOCKET.IO-BOILERPLATE

Introduction

A CLI to quickly create a basic set-up for applications using Express and Socket.io

The backend is based on NodeJS with express and socket.io.

The frontend consists of a simple landing page with HTML, CSS and JS and socket.io-client.

Requirements

Node v7.6.0 or higher for ES2015 and async function support.

Installation

To use the tool you can either install the package globally using:

npm i -g ewsb-template 

and then run the command

ewsb-template `${destination_folder_here}`

However, we reccomend using npx to ensure you always have the most up to date version.

npx ewsb-template `{destination_folder_here}

Getting Started

The package installs the required folder structure along with a fully integrated testing framework and example database of your choice.

It comes out of the box with environment variables, to allow you to easily run npm test, npm run dev, or npm start to run your program at whatever stage of development you are.

It also runs the following commands to get all the required dependencies to get your project up and running:

    npm i express, cors, dotenv, socket.io, socket.io-client
    npm i jest nodemon -D

Database

When you run the command, you will be prompted to enter what kind of database you will be working with.

This will generate an example structure for you to work with.

If you choose PostgreSQL, go to .env and update your username and password.

If you do not have the database already created then the server will not run

Whenever you're running the server or tests, make sure you have an open connection to the DB

Scripts

The database works with environment variables, depending whether you are in production, development or testing.

If you're on Windows, and get the following error:

'NODE_ENV' is not recognized as an internal or external command, operable program or batch file

run:

npm install --save-optional win-node-env

to set (common) environment variables.

Test

If you wish to run your tests, run:

npm test

The tests will start using your ${DB_NAME}_test.

These tests work out of the box, and feel free to modify them to meet your requirements as your code changes.

Make sure you have this database set up otherwise your tests will fail

Dev

If you wish to run your server in development, run:

npm run dev

This will run your server using nodemon with your database in ${DB_NAME}_dev, allowing you to make development changes without effecting the production.

Make sure you have this database set up otherwise starting your server will fail

Production

If you wish to run your server in production, run:

npm start

This will run your server using node with your database in ${DB_NAME}.

Make sure you have this database set up otherwise starting your server will fail

If you run your server without one of these scripts it will default to production

Testing Framework

We have included out of the box integration and unit testing.

Feel free to use these as a template for your future tests as your code grows.

There are 4 main areas we cover:

Model Testing
    The tests ensure that the models interact with the database as expected.
Controller Testing
    By mocking the services which interact with the models, these tests check that the controllers behave as expected.
Socket Testing
    By mocking the services, these tests isolate the sockets and ensure the connections and disconnections take place. They also ensure that they can emit and receive events as expected.
Integration Testing
    The integration test the flow of data from start to finish. Using mock data and the test database the tests are able to check that:
    - the controllers correctly pass information to the services
    - the services interact with the models as expected
    - the models succesfuly create, read, update, and delete information when interacting with the database.

Folder Structure

The express-socket-io-boilerplate generates the following folder structure:

└── your_project_name
    ├── public
    |   ├── index.html
    |   ├── style.css
    |   └── index.js
    |
    ├── server
    |   ├── app.js
    |   ├── index.js
    |   ├── integration.test.js
    |   ├── .env
    |   ├── controllers
    |   |       ├── messasge.controllers.js
    |   |       └── message.controllers.test.js
    |   ├── eventHandlers
    |   |       ├── index.js
    |   |       ├── newMessage.js
    |   |       ├── newSocket.js
    |   |       └── onDisconnect.js
    |   ├── models
    |   |       ├──index.js
    |   |       ├── message.models.js
    |   |       └── message.models.test.js
    |   ├── routers
    |   |   └─── router.js 
    |   ├── services
    |   |       ├──index.js
    |   |       ├──deleteMessage.js
    |   |       ├──getMessages.js
    |   |       ├── postMessage.js
    |   |       └── updateMessage.js 
    |   ├── sockets
    |   |       ├──index.js
    |   |       └── index.test.js 
    ├── package.json
    ├── package-lock.json
    └── .git