This example can be used to dockerize or to play around with NodeJS and Express.
Prerequisites:
mkdir node-helloworld
cd Desktop/node-helloworld
index.js contents:
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('Hello World!');
});
var server = app.listen(3000, function() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
package.json contents:
{
"name": "myhelloworld",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node index.js"
},
"engines": {
"node": "^v12.21.0"
},
"dependencies": {
"express": "^4.17.1"
}
}
Run:
npm install
npm start
To test - navigate to http://localhost:3000