git clone https://github.com/adilajjemami/express-typescript-boilerplate.git
cd express-typescript-boilerplate
yarn installLong live to Expressjs, Typescript and Yarn 🤘
Like most starter-kits and boilerplate projects, this project has a simple philosophy in other words : Be simple !
project
│
└───src
│ │ Server.ts
│ │ index.ts
│ │
│ └───Controller
│ | │ BaseController.ts // Abstr ct controller
│ | │ HelloController.ts // Controller example
| |
│ └───Core
│ | │ Core.ts // Application Core
│ | │ DependencyInjection.ts // Injection / import utility
| |
│ └───Middlewares
│ | │ ErrorMiddleware.ts // Expressjs middleware that return json response when an exception is thrown
| |
│ └───Services
│ | │ FakeService.ts // Service example
│ | │ HelloService.ts // Service example
| |
│ └───Utils
│ | │ ApiError.ts // Custom Error class
│ | │ GlobalMessage.ts // Get error object based on an errorCode
| |
│ └───config
│ │ config.ts // Global/shared configuration
│ │ configDev.ts // Development configuration. NODE_ENV=dev
│ │ configDev.ts // Production configuration. NODE_ENV=prod
│ │ configTest.ts // Production configuration. NODE_ENV=test
│ │ middlewares.ts // Middlewares configuration
│ │ parameters.ts // Application parameters
│ │ routing.ts // Apllication routing
│ │ services.ts // Services configuration
│
└───Resources
| │ errors.json // Global error messages
|
└───test // Unitests
└───dist // Dist files
import http from 'http';
import { Server } from './Server';
Server.boostrap()
.then((server) => {
// Create server
const httpServer = http.createServer(app);
// Start listening on port 3000
// You can override port by using NODE_PORT=8080
httpServer.listen(server.getPort());
});If you prefer async/await:
import http from 'http';
import { Server } from './Server';
...
const server = await Server.bootstrap();
// Create server
const httpServer = http.createServer(app);
// Start listening on port 3000
// You can override port by using NODE_PORT=8080
httpServer.listen(server.getPort());To lint the source code (tsLint):
npm run lintTo test the source code (mocha/chai):
npm run testTo dependencies check security issues (retirejs):
npm run security-checkerTo build the project:
npm run buildYou can run the server (dev):
npm run serve-dev