{"id":72,"date":"2014-12-26T02:50:25","date_gmt":"2014-12-26T02:50:25","guid":{"rendered":"https:\/\/www.tech.shinynewthings.com\/?p=72"},"modified":"2014-12-26T02:50:25","modified_gmt":"2014-12-26T02:50:25","slug":"express-path-to-static-files-bower-components-404-error","status":"publish","type":"post","link":"https:\/\/www.tech.shinynewthings.com\/?p=72","title":{"rendered":"Express Path to Static Files &#8211; Bower Components &#8211; 404 Error"},"content":{"rendered":"<p>Don&#8217;t get suckered into using the following line to reference static files like I did.<\/p>\n<p>app.set(express.static(__dirname + &#8216;\/bower_components&#8217;));<\/p>\n<p>One, it will often result in 404 errors and two it statically references directory separators.<\/p>\n<p>Instead use Path.<\/p>\n<p>Add this in the server file.<\/p>\n<p>path = require(&#8216;path&#8217;);<\/p>\n<p>And this line where appropriate.<\/p>\n<p>app.use(express.static(path.join(__dirname, &#8216;bower_components&#8217;)));<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Don&#8217;t get suckered into using the following line to reference static files like I did. app.set(express.static(__dirname + &#8216;\/bower_components&#8217;)); One, it will often result in 404 errors and two it statically references directory separators. Instead use Path. Add this in the server file. path = require(&#8216;path&#8217;); And this line where appropriate. app.use(express.static(path.join(__dirname, &#8216;bower_components&#8217;)));<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=72"}],"version-history":[{"count":1,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":73,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions\/73"}],"wp:attachment":[{"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech.shinynewthings.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}