From caf1a1bc0d1760106eb286d0e8d560a69cd8b28d Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 22 Aug 2016 22:07:36 -0400 Subject: [PATCH] static --- node.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/node.md b/node.md index 91b56a5..5a2be10 100644 --- a/node.md +++ b/node.md @@ -335,4 +335,17 @@ var valuesMatch = bcrypt.compareSync('does salted value match this?', saltedValu ``` ## Static + +If we have static files (JS, CSS, HTML, etc), we can put them in a directory used just for these kinds of files. Use this near the top of server.js: + +```javascript +app.use(express.static('public')); //set up a static asset dir in /public +``` + +Create a directory that matches the name passed to `express.static()`. Express will try to match requests with files in that directory + +- The route `/plain.html` would match the file `/public/plain.html` +- The route `/css/app.css` would match the file `/public/css/app.css` +- The route `/js/app.js` would match the file `/public/js/app.js` + ## Database