This video covers one solution to the serving static files challenge.
Serve static files with
Another common way to set up the
static middleware so that Express can serve static files from the 'public' folder (or any folder) located at the root of your application is with Node's
__dirname represents the directory name of the current module.
// Serve static files from the root of the application app.use( express.static(path.join(__dirname, 'public')) )
express.staticfunction is relative to the directory from where you launch your node process. If you run the Express app from another directory, it’s safer to use the absolute path of the directory that you want to serve (source).
// Serve static files by routing the static server to '/static' app.use( '/static', express.static(path.join(__dirname, 'public')) )
You need to sign up for Treehouse in order to download course files.Sign up