Skip to main content

First steps

Begin your journey with ExpressoTS, a TypeScript framework for building scalable and maintainable Node.js applications. This section guides you through the foundational concepts, setup, and architecture of ExpressoTS.

Why TypeScript?

TypeScript is a key element in developing robust server-side applications due to its strong typing, which significantly enhances code quality, scalability, productivity, and collaboration. Strong typing not only helps in catching errors early but also improves code documentation and maintainability, making TypeScript an excellent choice for large-scale applications.

Pre-requisites

Please make sure that Node.js version >=18.10.0 is installed on your operating system.

Setup

Install the ExpressoTS CLI globally using NPM to get started with your project setup:

Setting up a new ExpressoTS project is quite simple with ExpressoTS CLI. First install the CLI globally with NPM:

npm i -g @expressots/cli

Create a new project by running:

expressots new <project-name>

For a specific project structure and package manager, specify the template and package manager directly:

expressots new <project-name>  -p <package-manager> -t <template-name>

Project templates

ExpressoTS provides two project templates to cater to different development needs:

  • Non-opinionated: Offers flexibility in project structuring with minimal setup.
  • Opinionated: Comes pre-configured for complex projects, reinforcing a specific project structure and scaffolding pattern.

Non-opinionated project structure

project-name/
├── src/
│ ├── app.container.ts
│ ├── app.controller.ts
│ ├── app.module.ts
│ ├── app.provider.ts
│ ├── main.ts
├── test/
│ ├── app.controller.spec.ts
File NameDescription
app.container.tsDependency injection container. Organizes the application modules.
app.controller.tsA basic controller with a single route.
app.module.tsApplication root module.
app.provider.tsApplication lifecycle manager.
main.tsThe main entry point of an ExpressoTS application.
app.controller.spec.tsUnit test for the app.controller.

Opinionated project structure

project-name/
├── src/
│ ├── providers/
│ │ └── app/
│ │ └── app.provider.ts
│ ├── useCases/
│ │ └── app/
│ │ └── app.controller.ts
│ │ └── app.module.ts
│ │ └── app.usecase.ts
│ ├── app.container.ts
│ ├── env.ts
│ ├── main.ts
├── test/
│ ├── app.usecase.spec.ts
File NameDescription
providers/This folder contains the layer responsible to provide externals resources to the application, also known as adapters.
app/app.provider.tsApplication lifecycle manager.
useCases/The use case folder contains the use cases implementation of operations that can be performed in the application.
app.container.tsDependency injection container. Organizes the application modules.
env.tsThis is an utility resource that maps .env variables.
main.tsThe main entry point of an ExpressoTS application.
app.usecase.spec.tsA basic unit test for the app.usecase.

This structure provides a robust framework for developing API endpoints, showcasing the layering and organization capabilities of ExpressoTS.

Application initialization and Configuration

Initialize your application with the AppFactory.create() method, passing in the container and an App class for lifecycle management. This step is crucial for configuring your application's dependency injection and middleware setup.

async function bootstrap() {
const app = await AppFactory.create(container, App);
await app.listen(3000, ServerEnvironment.Development);
}

Running your application

With your application set up, start your development server or build your application with the following commands:

  • Development Mode: npm run dev
  • Production Build: npm run build
  • Production Mode: npm run prod
info

Once the application is up and running, you can access it by navigating to http://localhost:3000/.

Framework flexibility

ExpressoTS is a versatile framework that is not bound to any specific platform or technology. Leveraging popular Node.js libraries like InversifyJS and Express.js, it is designed to be lightweight, modular, customizable, and easy to use. Developers can expand the framework's capabilities by creating new providers that can be incorporated into their applications.


Support the project

ExpressoTS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider: