中文 (简体)
Fork Me on GitHub

This documentation is for SFN 0.4.x, for old version SFN documentation, please click here.

Initiate Your Project

Create a directory to store files of your project, then use the command

npm init

to initiate your project, assume you have some knowledge of NPM and have NodeJS installed.

Install TypeScript Compiler And Runtime

SFN is written in TypeScript, which your own code should be as well.

The runtime ts-node is optional, only needed if you want to run your program without compiling.

npm i -g typescript
npm i -g ts-node

Install PM2 (Optional)

Since version 0.3.x, SFN uses PM2 as its application manager and load-balancer, so to better deploy your application, you'd also install PM2 and use it to start you application (however it is production environment requirement, not necessary during development).

npm i -g pm2

Install Framework

After you have initiated your project, you can now install SFN by using this command:

npm i sfn

After all files downloaded, type the following command to initiate your project, it will create needed files and directories for you automatically.

But before running this procedure, you have to setup the environment for NodeJS to run user-defined commands. See Command Line.

sfn init

Start Demo Server

SFN provides a demo, so you can now start server and see what will happen.

If you have installed ts-node, use this command to start the project.

ts-node src

Otherwise, compile the source code with command: tsc, then run the command:

node dist

And the server should be started in few seconds.

If you have PM2 installed, you can use the following command to start the application, and auto-scale according to the CPU numbers.

pm2 start dist/index.js -i max