One of the first things that comes to mind when writing a web application is the ability to serve static files. While there are other solutions that we can use alongside our applications for this functionality, it's good to know that we can always load an Express middleware to take care of serving the static files.
Even though serving the static files isn't optimal with Node, it's worth knowing that existing modules can handle thousands of connections per second. If our web application doesn't have a traffic level that exceeds this, it's an option worth considering.
There are several modules that handle serving static files with Node for us, such as st
(https://www.npmjs.org/package/st) or
serve-static
(https://www.npmjs.org/package/serve-static), which come bundled with Express. We will be using the latter for the following example:
var express = require('express'); var app = express(); var ejs = require('ejs'); app.set('view engine...