Dirk Harriman Banner Image

 

Notes Node JS

Projects:

 

Project 2 - App2

A basic Hello World application without node_modules included.


 
 

index.html index.js package.json

<!DOCTYPE html> <html> <head> <title>Node JS Index Page</title> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="description" content=""/> <meta name="author" content=""/> </head> <body> <form> <div class="container"> <h1>Node JS Index Page</h1> </div> </form> </body> </html>

const http = require('http'); /* A core node.js package module */ const fs = require('fs'); const hostname = '127.0.0.1'; const port = 3100; fs.readFile('index.html', (err, html) => { if(err) { throw err; } const server = http.createServer((req,res) => { res.statusCode = 200; res.setHeader('Content-type','text/html'); res.write(html); res.end(); }); server.listen(port, hostname, () => { console.log('Server Started on Port: ' + port); }); });

{ "name": "app2", "version": "1.0.0", "description": "Second node app. Uses Express.", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { "express": "*", "body-parser": "*" }, "author": "Dirk Harriman", "license": "ISC" }