Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to learn node.js and create a web application, and although I'm doing my best to just use only node.js to create it, I'm having a very difficult time finding resources and examples that describe the process without using other frameworks or libraries.

Specifically, how can I serve HTML and CSS content without using hard-coded string variables, but serving up HTML and CSS files dynamically using just node.js?

share|improve this question
up vote 6 down vote accepted

Here you'll build a simple app without using any frameworks. Recommended to get a first touch at node: The Node Beginner Book » A comprehensive Node.js tutorial

The aim of this document is to get you started with developing applications with Node.js, teaching you everything you need to know about "advanced" JavaScript along the way. It goes way beyond your typical "Hello World" tutorial...

This document will probably fit best for readers that have a background similar to my own: experienced with at least one object-oriented language like Ruby, Python, PHP or Java, only little experience with JavaScript, and completely new to Node.js.

Aiming at developers that already have experience with other programming languages means that this document won't cover really basic stuff like data types, variables, control structures and the likes. You already need to know about these to understand this document.

However, because functions and objects in JavaScript are different from their counterparts in most other languages, these will be explained in more detail...

The URL router implemented there can easily be augmented to serve static files, using the fs module to read them on disk.

share|improve this answer
It has good explanation of the routing but hard coded html and static files is not so interesting. It would be fine to know principles of dynamic page generating (without import of any third-party libraries). – SerG Jul 22 '14 at 11:09

From what I understand you are trying to build a static file server on you own.This gist can be a good starting point.It does not give any explanation of the code but it is easy to understand.For instance take a look at this piece of code

var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888; 

Here 4 modules are being required.Now to know more about these modules all you got to do is go the node js api docs and read more about them.Node js 's API is very small and this is the best way to learn it.

Also while it can be a very good learning exercise to build a server of your own you should use an already built library for production.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.