From 83e38957fee740487969d23b13c54f800d368ae6 Mon Sep 17 00:00:00 2001 From: Adam Ross Date: Tue, 16 Oct 2018 09:02:21 -0700 Subject: [PATCH] serving/helloworld-nodejs: Respect the PORT env var --- serving/samples/helloworld-nodejs/README.md | 12 ++++++------ serving/samples/helloworld-nodejs/app.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/serving/samples/helloworld-nodejs/README.md b/serving/samples/helloworld-nodejs/README.md index e981f0c5686..b419ad8c8b0 100644 --- a/serving/samples/helloworld-nodejs/README.md +++ b/serving/samples/helloworld-nodejs/README.md @@ -1,8 +1,8 @@ # Hello World - Node.js sample A simple web app written in Node.js that you can use for testing. -It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}!". If -TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET. +It reads in an env variable `TARGET` and prints "Hello ${TARGET}!". If +TARGET is not specified, it will use "World" as the TARGET. ## Prerequisites @@ -52,13 +52,13 @@ recreate the source files from this folder. app.get('/', function (req, res) { console.log('Hello world received a request.'); - var target = process.env.TARGET || 'World'; - res.send('Hello ' + target); + const target = process.env.TARGET || 'World'; + res.send('Hello ' + target + '!'); }); - var port = 8080; + const port = process.env.PORT || 8080; app.listen(port, function () { - console.log('Hello world listening on port', port); + console.log('Hello world listening on port', port); }); ``` diff --git a/serving/samples/helloworld-nodejs/app.js b/serving/samples/helloworld-nodejs/app.js index e9ad188cc16..f2faf329f2e 100644 --- a/serving/samples/helloworld-nodejs/app.js +++ b/serving/samples/helloworld-nodejs/app.js @@ -20,11 +20,11 @@ const app = express(); app.get('/', function (req, res) { console.log('Hello world received a request.'); - var target = process.env.TARGET || 'World'; - res.send('Hello ' + target); + const target = process.env.TARGET || 'World'; + res.send('Hello ' + target + '!'); }); -var port = 8080; +const port = process.env.PORT || 8080; app.listen(port, function () { - console.log('Hello world listening on port', port); + console.log('Hello world listening on port', port); });