-
Book Overview & Buying
-
Table Of Contents
Javascript Unlocked
By :
We've just learnt how to write command-line scripts with Node.js. However, this run-time is mostly known as server-side JavaScript, meaning this is the software to run an HTTP-server. Actually, Node.js is especially great for this kind of job. If we launch a server application based on Node.js, it runs permanently, initialized only once. For instance, we may create a single DB connection object and reuse it whenever someone requests the application. Besides, it grants us all the flexibility and power of JavaScript including event-driven, non-blocking I/O.
So how can we make use of this? Thanks to the HTTP native module of Node.js, a simple web-server can be implemented as easy as this:
simple-server.js
"use strict";
/** @type {module:http} */
var http = require( "http" ),
/** @type {HttpServer} */
server = http.createServer(function( request, response ) {
response.writeHead( 200, {"Content-Type": "text/html"} );
response.write...
Change the font size
Change margin width
Change background colour