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

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); 
主站蜘蛛池模板: 新龙县| 阿瓦提县| 江城| 海兴县| 玉门市| 水城县| 商河县| 安国市| 高平市| 江口县| 潜山县| 习水县| 崇文区| 沂源县| 宁城县| 新化县| 叶城县| 桐庐县| 福州市| 六枝特区| 观塘区| 克什克腾旗| 渭源县| 晋城| 潍坊市| 如东县| 合肥市| 牡丹江市| 连云港市| 东莞市| 廉江市| 北票市| 泗阳县| 宣汉县| 美姑县| 丰城市| 和平区| 顺平县| 汽车| 旬邑县| 茶陵县|