Sorry for silly question but i really want to know why we need to use it . I know stactic file are files that aren't being generated as they're loaded, but must be sent to the browser when requested .
I would appreciate if anyone can explain for me these questions.
Imagine a scenario where you are creating an API as well as want to serve your static assets (HTML, CSS, JavaScript, etc) from the same Express application.
In this case it makes a lot of sense to define a folder - normally it's called 'public' - and have all the previously mentioned static assets there, e.g.:
app.use(express.static('public'))
Now that's out of the way you can go and create your API using Node.JS/Express with a nice separation of what's a static asset and what's loaded dynamically by your app. At least this is how I use it. I hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With