官术网_书友最值得收藏!

Getting ready

Express is so minimalistic that it doesn't come with any boilerplate code to get you started. There are a number of generators out there which can set up a structure for you, however, I'm going to stick to a simple web page and a WebSocket for testing. Here's my Express file:

var express = require('express'); 
var app = express(); 
var expressWs = require('express-ws')(app); 
 
app.get('/', function (req, res) { 
    res.send('Nginx demo!!!'); 
}); 
 
app.ws('/echo', function(ws, req) { 
    ws.on('message', function(msg) { 
        ws.send(msg); 
    }); 
}); 
 
app.listen(3000); 
主站蜘蛛池模板: 广东省| 夹江县| 宜阳县| 武清区| 巴林左旗| 乾安县| 赤壁市| 云和县| 凌源市| 太原市| 信宜市| 曲沃县| 武夷山市| 军事| 普格县| 吉林省| 延津县| 越西县| 历史| 孝义市| 旺苍县| 囊谦县| 万全县| 青田县| 铅山县| 威海市| 蒙山县| 神农架林区| 松原市| 财经| 客服| 曲松县| 临沧市| 台南市| 河北省| 青铜峡市| 禄劝| 黎平县| 商河县| 望奎县| 临泽县|