socket.io 官网给的例子都是需要先createServer后才能 require('socket.io')(server);
问题来了,express生成器生成的项目,createServer 是在最后/bin/www中创建的,该如何使用改写呢?
// socket.io 官网var app = require('express').createServer();var io = require('socket.io')(app); ... .../* express生成器生成的项目(下面这段是/bin/www文件) * 想在app文件中 require('socket.io'),不会了.... */var app = require('../app');var debug = require('debug')('TestServer:server');var http = require('http');/** * Get port from environment and store in Express. */var port = normalizePort(process.env.PORT || '3000'); app.set('port', port);/** * Create HTTP server. */
相关分类