How to import JavaScript library from CDN links in node.js script

I have a script called myscript.js

. I usually execute a script using this command:

$ node myscript.js

      

How to include JStat library via CDN address in script:

//cdn.jsdelivr.net/jstat/1.2.1/jstat.min.js

      

+3


source to share


1 answer


For node, there is no logic built into node.

If you are sure that this library supports server-side use (not all libraries are "isomorphic", that is, they can be used both client-side and server-side), then you can download it and require it locally ( require('./jstat.min.js')

).



The best way is to find it on npm and install it like any other node module.

Note. There is really no advantage to using cdn on the server side. The main use case for cdn is to provide a cached copy to users 'browsers, but users' browsers will not work with node code.

+5


source







All Articles