Create a new directory called hello-world and initialize a node project with npm init, similar to how we did previously. In Chapter 13, Using Express, we'll work with Express, a popular web server for Node.js. However, for now, we'll use a very bare-bones method of creating a page.
Start off your index.js script as follows:
const http = require('http')
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end("Hello, World!")
}).listen(8080)
As with fs and readline, http is built in to Node, so we don't have to use npm install to get it. Rather, this will work out of the box. Add a start script in your package.json file:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
Then fire it up!
Figure 11.2 - Executing npm start
OK, our output isn't super helpful, but...