Feathers實時JavaScript框架
Feathers是一個為將來應用程序準備的實時JavaScript框架。
開始安裝
你可以僅利用4個命令建立第一個實時API:
$ npm install -g yo generator-feathers $ mkdir my-new-app $ cd my-new-app/ $ yo feathers $ npm start
要了解更多關于Feathers請訪問 feathersjs.com 官網(wǎng)或直接進入了the Feathers docs。
看看如何工作
這里是所有你需要在內(nèi)存數(shù)據(jù)存儲中創(chuàng)建REST風格,實時消息API使用的代碼:
// app.js
var feathers = require('feathers');
var rest = require('feathers-rest');
var socketio = require('feathers-socketio');
var memory = require('feathers-memory');
var bodyParser = require('body-parser');
var handler = require('feathers-errors/handler');
// A Feathers app is the same as an Express app
var app = feathers();
// Add REST API support
app.configure(rest());
// Configure Socket.io real-time APIs
app.configure(socketio());
// Parse HTTP JSON bodies
app.use(bodyParser.json());
// Parse URL-encoded params
app.use(bodyParser.urlencoded({ extended: true }));
// Register our memory "messages" service
app.use('/messages', memory());
// Register a nicer error handler than the default Express one
app.use(handler());
// Start the server
app.listen(3000);
然后運行
npm install feathers feathers-rest feathers-socketio feathers-errors feathers-memory body-parser node app
并訪問http://localhost:3000/messages。 那就行了!利用Feathers你還可以做更多包括;使用一個真實數(shù)據(jù)庫,認證,授權,集群等等!跳轉到the Feathers docs,看看它是多么容易建立可擴展的實時應用程序。
評論
圖片
表情
