I am trying to place static files in my public folder such as the html,css and js files but they won't fetch to the get url ('/'). Here is my folder structure
app.js node_modules --express package.json public --style.css My app is:
var express = require('express'); var app = express(); var port = process.env.PORT || 3000; app.use('/assets', express.static(__dirname + '/public')); app.get('/', function(req, res){ res.send('<html><head><link href=assets/style.css type=text/css rel=stylesheet/></head><body><h1>Hello World</h1></body></html>'); }); app.get('/person/:id', function(req, res){ res.send('<html><head></head><body><h1>Person: ' + req.params.id + '</h1></body></html>'); }); app.get('/api', function(req, res){ res.json({ firstname: 'John', lastname: 'Doe' }); }); app.listen(port); Style code is:
style.css: body { font-family: Arial, Helvetica, sans-sarif; }
assets/come from in your HTML?but they won't fetch to the get url ('/'). Do you mean that if you putassets/style.cssprefixed with your host into the adressbar of your browser then you don't see the content of your css file? What message is shown to you instead?"or') are optional in this given example because the value of the attribute does not contain any character that requires quoting. W3C: 4.4. Attributes[...]an unquoted attribute value has the following restrictions: must not contain any literal space characters, must not contain any """, "'", "=", ">", "<", or "`", characters, must not be the empty string[...]