This code is working in Azure
var http = require('http');
var port = process.env.port || 1337;
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
whereas the code is written below throws error '.azurewebsites.net is currently unable to handle this request. HTTP ERROR 500'. In Application logs it shows "Application has thrown an uncaught exception and is terminated: SyntaxError: Use of const in strict mode." Please suggest what could be the problem. Currently using node version 9.2.0 also tried changing the version to 8.11.3 in both package.json as well as application settings.
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
var port = process.env.PORT || 1337;
app.listen(port);
function handler(req, res) {
fs.readFile(__dirname + '/page.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.on('connection', function (socket) {
console.log((new Date()) + ' Connected to server socket');
socket.emit('message', {
msg: 'Connected! Greetings from server!'
});
socket.on('message', function (data) {
console.log((new Date()) + ' Message: ' + data);
socket.emit('message', {
msg: 'Message received from client: ' + data
});
});
socket.on('disconnect', function () {
console.log((new Date()) + ' Disconnected!');
});
});