I am Hack Sparrow
Captain of the Internets.

Archive for Express.js

My book on Express.js is published

I have been blogging about Express.js for quite some time now. Early this year, I was contacted by Packt, enquiring me if I'd be interested in writing a book on Express. A year ago, I had this idea to write a book on Express, which would be titled "Mastering Express.js", and worked out an early-stage table of contents for it. So when Packt contacted me, I told them that I would, in fact, be very interested in writing a book on Express. Sin ...

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 ...

Express.js HTTPS Server Client Example

In this tutorial I will show you how to set up an HTTPS ExpressJS server and connect to it using a TLS client. I will assume you already know how to set up a basic Express.js app, if not read this tutorial. Create an Express app, and use the following code as the server: [code] var fs = require('fs'); var express = require('express'); var https = require('https'); var key = fs.readFileSync('./k ...