Problem scenario
You want to write a "Hello World" program using Node.js. What do you do?
Solution
Prerequisite
Identify the external IP address of the server (e.g., run "curl icanhazip.com" if you have access to the internet).
Procedures
1. Install node and npm on a Linux server. If you need assistance with this, see this posting.
2. Run these two commands:
mkdir contint
cd contint
3. Run this command:
npm init # respond to the interactive prompts. You probably will want to accept the defaults, but for the "Entry point" one with the suggestion of "index.js" change it to "contint.js"
For "Is it ok?" type "yes" (with no quotes) and press "Enter".
4. Create a file called contint.js and have the following as content:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World');
});
app.listen(2987, function () {
console.log('Example webpage application listening on port 2987!');
});
5. Run these two commands:
npm install express --save
node contint.js
6. Open a web browser on your workstation. Go to x.x.x.x:2987 where x.x.x.x is the external IP address of the Linux server.