sfn
A Service Framework for Node.js.
Last updated 2 months ago by hyurl .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sfn 
SYNC missed versions from official npm registry.

Service Framework for NodeJS

A Service Framework for NodeJS.

For documentation, please visit sfnjs.com.

How To Use?

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.

Prepare TypeScript Environment

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

npm i -D typescript
npm i -D @types/node

Optionally, you can install ts-node to run the program without compiling source code.

npm i -D 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.

tsc
node dist

And the server should be started in few seconds.

ts-node --files src # --files flag must be provided

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

Write Your First Controller

You can see that there is a folder named src/controllers generated in your project, it's where you're going put you controller files in.

You may open and edit the demo files in it, but here I'm going to show you how to create a new one (with TypeScript).

Create a file in src/controllers, named Demo.ts:

import { HttpController, route } from "sfn";

export default class extends HttpController {
    @route.get("/demo")
    index() {
        return "Hello, World!";
    }
}

Now restart the server, you will see Hello, World! when you visit http://localhost/demo.

Why Using SFN?

SFN provides a very easy-to-use and efficient API, you can just write few lines of code, and the frame work will handle other stuffs for you. One of the principles in SFN is: If the framework can do the work, then the user shouldn't do it.

For such a goal, SFN provides many features, etc. shared session, simple file uploading, error handling, multi-processing, etc. You don't need to worry how the framework does those jobs, just focus on your own design.

Additionally, SFN is written in TypeScript, the strong-typed language instead of pure JavaScript, it's way more safer than just using JavaScript for a strong and featured web program.

License

SFN is licensed under MIT, you're free to use.

Run Test

SFN currently doesn't provide any unit tests of the framework (but dependency modules do), the only way to test it is simply clone the repository from GitHub to your computer, install all the dependencies and run the built-in documentation website.

git clone https://github.com/hyurl/sfn
mkdir ./node_modules
ln -s ./sfn ./node_modules/sfn # some modules require sfn in node_modules
cd sfn
npm i
tsc
node dist/doc-server # SFN 0.5.x uses separeated documentation service

And open a new terminal, use the following command to start the web server.

node dist

And the doc server will started, note that the server port is 80 by default, if it's not available on your machine, simply modify it in .env file before running the application.

TODO List

  1. Distributed Cache Service
  2. Distributed Email Service
  3. Distributed Logging Service

Current Tags

  • 0.0.0                                ...           beta (2 years ago)
  • 0.5.11                                ...           latest (2 months ago)

50 Versions

  • 0.5.11                                ...           2 months ago
  • 0.5.10                                ...           2 months ago
  • 0.5.9                                ...           2 months ago
  • 0.5.7                                ...           5 months ago
  • 0.5.6                                ...           5 months ago
  • 0.5.5                                ...           5 months ago
  • 0.5.4                                ...           5 months ago
  • 0.5.3                                ...           6 months ago
  • 0.5.2                                ...           6 months ago
  • 0.5.1                                ...           6 months ago
  • 0.5.0                                ...           6 months ago
  • 0.4.5                                ...           8 months ago
  • 0.4.4                                ...           8 months ago
  • 0.4.3                                ...           8 months ago
  • 0.4.2                                ...           8 months ago
  • 0.4.1                                ...           8 months ago
  • 0.4.0                                ...           8 months ago
  • 0.3.7                                ...           10 months ago
  • 0.3.6                                ...           a year ago
  • 0.3.5                                ...           a year ago
  • 0.3.2                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.7                                ...           a year ago
  • 0.2.6                                ...           a year ago
  • 0.2.5                                ...           a year ago
  • 0.2.4                                ...           a year ago
  • 0.2.3                                ...           a year ago
  • 0.2.2                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.20                                ...           a year ago
  • 0.1.16                                ...           a year ago
  • 0.1.15                                ...           a year ago
  • 0.1.14                                ...           a year ago
  • 0.1.13                                ...           a year ago
  • 0.1.12                                ...           a year ago
  • 0.1.11                                ...           a year ago
  • 0.1.10                                ...           a year ago
  • 0.1.9                                ...           a year ago
  • 0.1.8                                ...           a year ago
  • 0.1.7                                ...           a year ago
  • 0.1.6                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 3
Dependencies (47)
Dev Dependencies (15)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |