A fully configurable Node.js, Express, and TypeScript server template with a service-based architecture that can interact with MySQL, PostgresSQL, Sqlite, MariaDB, MSSql, DB2, Snowflake, Oracle, MongoDB. Out-of-the-box validation, documentation generation, and more.
- Node.js, Express, TypeScript: Robust server setup using Node.js, Express, and TypeScript.
- Sequelize: Integration with Sequelize for SQL database operations.
- Mongoose: Integration with Mongoose for MongoDB database operations.
- Database Compatibility: Interact with MySQL, PostgreSQL, MariaDB, Sqlite, MSSql, MongoDB.
- Validation Mechanism: Pre-built validations for request payloads.
- Automated Swagger Documentation: Automatically generated documentation available at
/api-docs
. - Service-Based Architecture: Modular approach for better organization and scalability.
- Socket Events: Socket event handling using Socket.io.
- Docker: Dockerized for easy deployment.
- Swagger documentation auto-generated for all routes.
- Accessible at
/api-docs
. - Generated using the
doc
method in theMasterController
class and Joi validation schemas.
The MasterController
is the backbone, providing functionalities for managing HTTP requests, socket events, payload
validation, and more.
- Controller Logic Handling:
restController
method manages HTTP requests. - Socket Event Handling:
socketController
method manages socket events. - Payload Validation:
joiValidator
method validates incoming request payloads. - Swagger Documentation Generation:
doc
method generates Swagger documentation. - Route Handling:
get
,post
,put
, anddelete
methods register routes within the Express router.
Extend the MasterController
to create controller classes for specific routes or socket events. Use the provided
methods for efficient request handling, validation, and documentation generation.
Clone this repo to your local machine using `
$ git clone https://github.com/Thre4dripper/NodeTs-Express-Service-Based-Template
Install dependencies
$ npm install or yarnStart the server
$ npm run dev or yarn devBuild the project
$ npm run build or yarn buildRun the project
$ npm run start or yarn start
Additional dependencies are required for database operations. Install the appropriate dependencies for your database dialect.
$ npm install mysql2$ npm install pg pg-hstore$ npm install sqlite$ npm install mariadb$ npm install tedious or mssql$ npm install ibm_db$ npm install snowflake-sdk$ npm install oracledb$ npm install mongoose
PORT
- Port number for the server to run on.DB_DIALECT
- Database dialect to use. (Options: mysql, postgres, mariadb, sqlite, mssql, mongodb)DB_HOST
- Database host.DB_PORT
- Database port.DB_USER
- Database username.DB_PASS
- Database password.DB_NAME
- Database name.MONGO_URI
- MongoDB URI (Only for MongoDB Dialect).JWT_SECRET
- Secret key for JWT.$ docker build -t <image-name> .$ docker run -e <env-variable>=<value> -p <port>:<port> <image-name>$ docker run -d -e <env-variable>=<value> -p <port>:<port> <image-name>$ docker stop <container-id>$ docker rm <container-id>$ docker rmi <image-name>$ docker ps -a$ docker ps
Contributions are welcome! Please feel free to submit a Pull Request.