How to link libraries and dependencies when deploying a website

Solution for How to link libraries and dependencies when deploying a website
is Given Below:

I have a hard time understanding how libraries and other dependencies work in the server. It is fairly simple when we develop in our local server. You just download dependencies like barbajs using npm or yarn or you can use a CDN. How does this work in the server. For example, I am using firebase to host my portfolio website. Should I download JS libraries like barbajs to the server or is it enough if I download it in my local host. I know I can use CDN, but I am curious about other ways of doing this like using npm.