Loading repository data…
Loading repository data…
MrDay2Day / repository
This is a simple Express REST server with with SocketIo distributed through Redis/KeyDB, and Database integration MySQL, PostGresSQL and MongoDB, and Server-side Events.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Created by: MrDay2Day
Node Version: v22.6
Short answer: A Boilerplate NodeJS Express Server Template written in Typescript built for scale!
The not so short answer: This is a work-in-progress boilerplate Typescript written Express REST Server with integrated WebSocket & -> RedisKeyDB/ValKey. This template is design to operate at scale using -> RedisKeyDB/ValKey and can easily be deployed as a node cluster or/and on separate machines locally or/and globally.
This template has built-in file management using S3 (Simple Storage Service) protocol and an emailing engine that can send raw html emails with attachments through AWS SES (Simple Emailing Service).
Simple I am a developer who creates a lot of servers & micro-services and I often find myself copying and pasting from previous projects the same code. So I said to myself why not just create a general template that has all the things I use most in my favorite worse language Javascript with a bit of seasoning being Typescript.
So I've integrated some 3rd party packages and services which I know a lot of people will love and also so honorary mentions from my favorites' list.
Well, that is because of the whole license issue and performance. In multiple test KeDB out performed Redis by a significant amount. KeyDB/ValKey might not be fully up-to-date with Redis 7 however it still has most of the main features of Redis to be used as an alternative for cache store, database & Pub/Sub(amongst other key features).
You are still able to use Redis if it and it's license doesn't affect your needs.
Copy and paste .env.template to .env
cp .env.template .env
Then edit the .env file with the necessary credentials. Input the required information for the services/features/libraries which will be used.
You are able to use multiple databases in this template whether individually or all at once PostGres, MySQL and MongoDB.
You are able to auto create Database and Tables/Collections on the fly when server starts up.
NB: Database can be activated of deactivated based on the *_ACTIVE (* = MONGO | PG | MYSQL) variable y is for active, leave blank if not active eg: MYSQL_ACTUVE=y.
After Environment variables are setup in the .env file you need to do a ci(Continuous Integration) installation of the node_modules:
npm ci
To start server in development mode and compile to vanilla Javascript then run with nodemon use:
npm run dev
To run Typescript using ts-node:
npm run ts-dev
This template allows you to use Docker for both development and production. As a developer you are free to make any changes you see fit to customize the development environment. If you do not know what you are doing do not edit any changes.
To start development in Docker you can use the shell script, this starts the development server in docker using user Node v22.6 with ts-node executing Typescript.
./app.sh docker-dev
To user nodemon while compiling Typescript to Javascript
./app.sh docker-dev-node
Deploying on server the simple way.
npm run start
This does a Typescript compilation then executes the Javascript code via 'code/server.js'
If you have any issues as it relates to type errors can also do a manual compilation by using:
npm run tsc
then:
npm run start-server
The npm run start-server command runs the 'code/server.js' directly
To do a production deployment using Docker, use the app.sh script.
A simple deployment is as follows:
./app.sh docker-prod
This will deploy a single container of the server.
You are able to deploy as a cluster for availability and load balance using nginx. The environment variable CLUSTER_SIZE is use to determine the cluster's size.
To Deploy use the following script:
./app.sh docker-cluster
To deploy using PM2 is simple just use the following script:
./app.sh pm2-deploy
This will deploy a PM2 cluster of the server. To restart the cluster simple use:
./app.sh pm2-restart
To stop the cluster you just need to run
./app.sh pm2-stop
To change Node version ensure your change the version in package.json:
{
"engines": {
"node": "22.6" << Change here
},
...
}
..and also the Node version in the docker-compose-*.yml files are controller by the .env file:
PORT=3330
To adjust cluster size for deployment using Docker or PM2 edit .env file
CLUSTER_SIZE=5
This will deploy a cluster with 5 nodes.
| Title | Code Example | Description |
|---|---|---|
| Random Number Generator | getRandomNumber(number, number) | Takes in a high and low number and returns a random number in-between both. |
| Random String Generator | generateString(length) | Great for creating temporary passwords with uppercase, lowercase, number & special character. |
| JSON Data Checker | checkJSONToData<DataType>(JSON) | Check if a string is JSON and if it is the expected type structure. |
| Random select from Array | getRandomElement<ArrayDataType>(array) | Randomly select an element from an array. |
| String to Number Converter | isStringNumber(string) | Converts a string to a number if possible. |
These are features & technologies that may or may not be integrated in the future.
| Icon | Status |
|---|---|
| ✅ | Completed |
| ➡️ | In Progress |
| ✏️ | Planning |
| 💭 | Considering |
| ⚠️ | Issue |
| ❌ | Cancelled |
| Icon | Implementation |
|---|---|
| 💡 | Custom Implementation (Custom implementations with docs & examples) |
| 🕯️ | Standard/Traditional Implementation |
| ❓ | Not Sure |
| Status | Feature | Implementation | Notes |
|---|---|---|---|
| ✅ | MySQL | 💡 | Industry "go to" for database. |
| ✅ | PostGrSQL | 💡 | Large community of extension. |
| ✅ | MongoDB | 💡 | Recommended DB for Scale and large amount of data. |
| ✅ | Socket.IO | 💡 | Realtime Communication between client and server. |
| ✅ | 💡 | Pub/Sub implementation ONLY used for cluster communication, can be used as DB cache with your own implementation. | |
| ✅ | Multer | 💡 | File Management for form-data uploads. |
| ✅ | Backblaze | 💡 | S3 Storage - Private & Public. |
| ✅ | Dockerize | 🕯️ | For Development and Production Deployment. |
| ✅ | Custom Task Queue / CRON / Email with AWS-SES | 🕯️ | Implemented however I created a mico-service repo for when deploying at scale. |
| ✅ | ts-node/ts-node-dev | 💡 | TypeScript execution engine.(Strict type requirements) |
| ➡️ | ServerSide Events with Example | 💡 | To be distributed through data stream for deployment at scale. |
| ➡️ | Kafka | 💡 | Data Streaming. |
| ✏️ | SMS | 🕯️ | Unable to find a suitable provider. |