Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

jQuery, pug, express help please.

I am doing a side/practice project with jQuery plugins and i cannot get my scripts to load on my pug template. It keeps 404ing.

1 Answer

With express you need to specify your static files. In your app.js file where your express server is instantiated do the following:

app.use(express.static(__dirname+'/public'));

Now put all your static files (css, javascript) into the '/public' folder which needs to be placed in the root just like app.js. In /public have a folder /css and /js. So in the end the structure might look like

views
public
--css
--js
---jquer
---main.js
app.js

This will just tell express which files should be available outside of your server.