1.8 KiB
1.8 KiB
id | title | challengeType |
---|---|---|
587d7fb0367417b2b2512bf0 | Serve Static Assets | 2 |
Description
express.static(path)
, where the parameter is the absolute path of the folder containing the assets. If you don’t know what a middleware is, don’t worry. We’ll discuss about it later in details. Basically middlewares are functions that intercept route handlers, adding some kind of information. A middleware needs to be mounted using the method app.use(path, middlewareFunction)
. The first path argument is optional. If you don’t pass it, the middleware will be executed for all the requests.
Mount the express.static()
middleware for all the requests with app.use()
. The absolute path to the assets folder is __dirname + /public
.
Now your app should be able to serve a CSS stylesheet. From outside the public folder will appear mounted to the root directory. Your front-page should look a little better now!
Instructions
Tests
- text: Your app should serve asset files from the <code>/public</code> directory
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/style.css'').then(data => { assert.match(data, /body\s*\{[^\}]*\}/, ''Your app does not serve static assets''); }, xhr => { throw new Error(xhr.responseText); })'
Challenge Seed
Solution
// solution required