From d2c41775e5fb44c6b8c6d0badc75850cc689f46a Mon Sep 17 00:00:00 2001 From: Claudio Cardinale Date: Tue, 30 Aug 2016 11:39:20 +0200 Subject: [PATCH] port number retrieved by env var --- index.js | 6 ++++-- package.json | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a322dca0..4795204e 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); +var dotenv = require('dotenv').load(); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); @@ -12,6 +13,7 @@ io.on('connection', function(socket){ }); }); -http.listen(3000, function(){ - console.log('listening on *:3000'); +var port = process.env.PORT || 3000; +http.listen(port, function(){ + console.log('listening on *:'+port); }); diff --git a/package.json b/package.json index 46f75814..9571af56 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.1", "description": "my first socket.io app", "dependencies": { + "dotenv": "^2.0.0", "express": "4.10.2", "socket.io": "1.2.0" }