I am Hack Sparrow
Captain of the Internets.

Express.js Custom Error Pages – 404 and 500

Express does a good job of handling 404 and 500 errors by default. However, many a times, the error is page is now what we would like it to look like. Is there a way to customize it? Yes there is. Online, you will come across many ways of implementing custom error pages for Express, but a lot of them do not use the correct approach, and those who do, do not explain properly how to do it, or what is going on. In this post I will show you how to create custom 404 and 500 error pages the right ...

How to serve static HTML files in Express.js

Express.js comes with a badass HTML pre-processor, Jade, but sometimes you may just want to use the good old HTML files for whatever reason. Is there a way to accomplish this? Oh yes, there is! The short and quick answer to this requirement is - dump the files in the [obj]public[/obj] directory! There is a slightly more elaborate but cleaner method, which will help you from cluttering up your [obj]public[/obj] directory with the HTML files - use the [obj]static[/obj] middleware. Create ...

vhost in Express.js

Wondering how to replicate the Apache , it allows a web server to listen on a single port and serve different web apps depending on the domain name or the subdomain. Implementing such a feature in Express.js is very easy. Before we can see how is implemented in Express.js, we would need to play a little trick on our PC: [code] $ sudo vi /etc/hosts [/code] Append these entr ...

How to Write Middleware for Connect / Express.js

If have reached to the point of wanting to write your own Express.js middleware, probably you know that Express.js is actually Connect (with additional features). If you didn't know that already, probably you should take it easy and learn more about Connect first. If you know what Connect is and want to write a middleware for it, you have come to the right place. Also I will show you ho ...

Express.js Tutorial

Looking for a good tutorial on Express.js to help you get quickly productive in it? You have come to the right place. [notice] This tutorial is for Express 3, the current version is Express 4. Unless you want to use Express 3, consider the tutorial outdated. [/notice] In this tutorial I will run you through the process setting up an Express.js app and making it do what a basic website might do. You will learn the basics of routes, views, Jade templates, Stylus CSS engine, handling POST a ...