使用npm安装后如何使用节点项目添加jquery?

我已经用npm(npm install jquery –save)安装了jquery,并将jquery添加到我的node_modules文件夹中。 我在html页面上的脚本标记使用什么路径?

这是我的目录结构的样子(仅包含必要的内容)

-Project Root -node_modules -jquery -dist -jquery.js -src -index.js -index.html -package.json 

对于socket.io,它看起来像这样

  

我试过这个用于jquery,但它没有用

  

任何帮助将不胜感激! 谢谢!

您不需要安装jQuery节点模块来在客户端运行jQuery。 您应该能够从公共或静态目录加载它。 例如,

您的项目结构

 -Project Root -public -js jquery.js -node_modules -index.js -index.html -package.json 

HTML

        ... stuff ...   

app.js

我假设您正在使用Express,就像Socket.IO入门示例中推荐的那样。 http://socket.io/get-started/chat/因此,在您的app.js中,您需要声明您的公共或静态位置。 这将允许您的index.html访问该文件夹中的文件。

 app.use('/public', express.static('public')); 

快递服务静态:

http://expressjs.com/starter/static-files.html