Build a simple Node server to respond to a get request.
1.1 Optional Starting Points
There are alot of great starting points for an ExpressJS based application. Check some of them out here: Express Frameworks
This project starts from scratch.
1.2 Create Basic Structure
mkdir public && mkdir views && touch readme.md && touch notes.md && touch .gitignore && touch app.js
1.3 Setup Git
git init && git add . && git commit -m
Add Gitignore: Copy from gitignore.io
1.4 Require HTTP Module
http
is a core module of NodeJS so all we need to do is require it. This module will that handles http requests.
@ app.js
var http = require('http');
1.5 Create server
@ app.js
var myServer = http.createServer(function(request, response){ });
1.6 Write response
@ app.js
var myServer = http.createServer(function(request, response){ response.writeHead(statusCode: 200, {"Content-Type" : "text/plain"}) response.write('Chat that word'); response.end(); });
1.7 Listen
@ app.js
myServer.listen(3000);
1.8 Run app
@ terminal
node app.js
1.9 Serve HTML
@ app.js
var myServer = http.createServer(function(request, response){ response.writeHead(200, {"Content-Type" : "text/html"}) response.write('<h1>Chat that word</h1>'); response.end(); });
1.10 Commit changes
git add . && git commit -m