< Homepage

DM Experiment - Build a dumb NodeJS server

Objective

Create a NodeJS HTTP server that:

  1. runs on your local machine on port 1234
  2. print to console "Server is listening." when server is ready to receive request
  3. returns this dynamic text as response:
    Request <request_method> <request_uri> received at <date>
Example:
When accessed at http://127.0.0.1:1234/toto, your server should reply:

Request GET /toto received at Tue Nov 18 2014 18:42:11 GMT+0100 (CET)

Prerequisites

A recent / working NodeJS installation (ex: NodeJS v0.10.*).

Instructions

  1. Keep it fun and simple!
  2. Do it quick and dirty! Do not reach for perfection (you know what I mean)!
  3. Do not spend for than the expected time. If you're having a hard time ask for help or have a look at the solution.
  4. Have fun and if you want to, read more about the experiment subject once you're done.
    Curiosity is the path to knowledge.

To be resolved before

22, January 2015

Expected time to resolution

Less than 1 hour

Expected number of lines

Less than 20

How

http://nodejs.org/api/http.html

Lost?

  • In the documenation, look for: http.createServer
  • http.Server.listen

Definitely lost?

Show solution