Steps to configure Node server:
- run node js server using command:
node server.js
- Configuration of server.js
var fs = require('fs'); var https = require('https'); var express = require('express'); var app = express(); var options = { key: fs.readFileSync('ssl_key.key'), cert: fs.readFileSync(' ssl_certificate.cer') }; var serverPort = 3001; var server = https.createServer(options, app); var io = require('socket.io')(server); io.on('connection', function(socket) { console.log('new connection'); }); app.use('/', function(req, res){ res.sendFile(__dirname + '/index.html'); var msg = ; req.on('data', function(chunk) { msg += chunk.toString(); console.log('Console msg %s',msg); io.emit('MSG', msg); }); req.on('error', function() { console.log('in req on'+msg); }); }); server.listen(serverPort, function() { console.log(serverPort); });
No comments:
Post a Comment