最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to import JavaScript library from CDN links in a node.js script - Stack Overflow

programmeradmin3浏览0评论

I have a script called myscript.js. I execute the script usually using this mand:

$ node myscript.js

How can I include the JStat Library via the CDN address in the script:

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

I have a script called myscript.js. I execute the script usually using this mand:

$ node myscript.js

How can I include the JStat Library via the CDN address in the script:

//cdn.jsdelivr/jstat/1.2.1/jstat.min.js
Share Improve this question asked Jul 6, 2015 at 8:07 neversaintneversaint 64k143 gold badges323 silver badges493 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

There isn't any logic built into node's require to do this.

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

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

Note: There isn't really an advantage to using a cdn on the server side. The main use case for a cdn is providing a cacheable copy to users' browsers, but users' browsers won't be running node code.

发布评论

评论列表(0)

  1. 暂无评论