node.js, express.js - What is the easiest way to serve a single static file?

express, node.js

Solution

`res.sendFile(path_to_file);` is all you need; it will automatically set the correct headers and transfer the file (it internally uses the same code as `express.static`).

In express versions less than 4, use `sendfile` instead of `sendFile`.

Problem

I have already seen and made use of: ``` app.use("/css", express.static(__dirname + '/css')); ``` I do not wish to serve all files from the root directory, only a single file, 'ipad.htm'. What is the best way to do this with the minimum amount of code, using express.js?

Original source

Related problems