Getting Started

IMPORTANT

It is not for beginners. It is recommended that you have some experience with TypeScript and JavaScript before you start using Mango Framework.

Requirements

Decorators

Your project must support emitDecoratorMetadata and experimentalDecorators options. Usually this is done by adding the following to your tsconfig.json or jsconfig.json file. It depends what compiler you are using.

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
    }
}
json

Dependecies (Packages)

Mango Framework has two packages, one for the server-side code and one for the client-side code. You can install them both using the following commands:

Server

npm install --save @altv-mango/server
sh

Client

npm install --save @altv-mango/client
sh

Preparing the Application

Starting an application involves several steps. One of them is creating the application builder.

App Builder

To initialize the application module tree (the root module and its children), the application builder has to be created first. You can do this using the createAppBuilder function from the @altv-mango/server or @altv-mango/client package.

+
+
import { createAppBuilder } from '@altv-mango/server'; 
// OR
import { createAppBuilder } from '@altv-mango/client'; 

const appBuilder = createAppBuilder();
typescript

Global Error Filters, Guards, Interceptors and Pipes

The Application Builder also allows you to register global error filters, guards, interceptors, and pipes. These are used for all controllers.

appBuilder.useGlobalFilters(MangoSeedFilter, MangoRipenessFilter, ...);
appBuilder.useGlobalGuards(MangoSeedPipe, MangoRipenessPipe, ...);
appBuilder.useGlobalInterceptors(MangoSeedInterceptor, MangoRipenessInterceptor, ...);
appBuilder.useGlobalPipes(MangoSeedPipe, MangoRipenessPipe, ...);
typescript

Learn more about error filters, guards, interceptors, and pipes in the following sections:

Other Options

The onModuleDestroy(), beforeAppShutdown() and onAppShutdown() hooks are called in the terminating phase (in response to an explicit call to app.close()).

Shutdown hook listeners consume system resources, so they are disabled by default. To use shutdown hooks, you must enable the listeners by calling enableShutdownHooks().

appBuilder.enableShutdownHooks();
typescript

In the client-side application, you can also add a WebView using the addWebView method.

appBuilder.addWebView(id, options);
typescript

If you want more control over the application, you can use plugins. Plugins are used to add extra functionality to the application.

appBuilder.usePlugins(MangoSeedPlugin, MangoRipenessPlugin, ...);
typescript

Learn more about plugins in the

Plugins
section.

Building the Application

Once you have registered all global error filters, guards, interceptors, and pipes, you are ready to build the application.

const app = appBuilder.build();
typescript

App

The application has two methods, start and stop. The start method starts the application and the stop method stops the application.

Starting the Application

Once you have built the application, you can start it. To start the application, you must call the start method and pass the root module as an argument.

The root module is the module that contains all the other modules. More about modules can be found in the

Modules
section.

await app.start(DeliciousMangoModule);
typescript

Stopping the Application

To stop the application, you need to call the stop method.

await app.stop();
typescript
Last update at: 2024/06/18 19:03:08