DEV Community

Cover image for Day 27 – Working with Static files - Learning Node JS In 30 Days [Mini series]
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Originally published at blog.nerdjfpb.com

Day 27 – Working with Static files - Learning Node JS In 30 Days [Mini series]

Lets do a fun thing, start a stylesheet on our profile page. like -

Alt Text

Now let's write a little bit of css

Alt Text

Add the css class in our current profile.ejs page

Alt Text

now check the browser, sadly know change. Do you know the reason ?

Alt Text

Because we can access that static files. Because we didn't make any static files route. Let's add this in app.js so that we can get the static files.

We can use a inbuilt express middleware to access that static folder which will created. Just using app.use('/assets', express.static('assets')) will give access to the /assets folder.

Alt Text

Now we can go to browser and see out it change

Alt Text

In app.use('/assets', express.static('assets')) In 1st part is route and 2nd part is folder that we are going to put the files.

Alt Text

So, can you work with the static files now?

You can see the graphical version here

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin !

You can read the old posts from this series (below)

Oldest comments (0)