简体   繁体   English

有效使用Node.js库

[英]Using Node.js library effectively

I just got started with Node.js and found that we need to RequireJS library on the backend. 我刚开始使用Node.js,发现我们需要在后端使用RequireJS库。 Also, we need to include it in view if we want to use it there. 另外,如果要在此处使用它,则需要将其包括在视图中。 So, if I want to use d3 to manipulate some data I will specify require in backend and send the result only to front end? 因此,如果我想使用d3处理某些数据,我将在后端指定require并将结果仅发送到前端? Or should I include it in both server side and HTML page? 还是应该在服务器端和HTML页面中都包含它? So is it redundant that using same library on both sides? 那么在两侧使用相同的库是否多余?

For jQuery: I did 对于jQuery:我做到了

npm install jquery

For Bootstrap: 对于引导程序:

npm install bootstrap

Now as the version does not match, I am including different jQuery in HTML file. 现在由于版本不匹配,我在HTML文件中包含了不同的jQuery。 Again I added d3 from scripts. 我再次从脚本中添加了d3。 Although it works, is this the proper way to design a Node.js app? 尽管可行,但这是设计Node.js应用程序的正确方法吗?

You do not want to use npm for the client side part of the application (bootstrap included). 您不想将npm用于应用程序的客户端部分(包括引导程序)。 I would recommend installing bower. 我建议安装凉亭。

npm install bower bower init

Create a .bowerrc file and put in it { "directory" : "public/components"} 创建一个.bowerrc文件,并将其放入{ "directory" : "public/components"}

bower install bootstrap --save

Include the script in the html file. 将脚本包括在html文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM