如何在Express应用程序中使用带有npm的jQuery? [英] how to use jQuery installed with npm in Express app?
问题描述
我有一个node.js + express应用程序,我在npm中安装了jQuery。
I have a node.js + express app and I installed jQuery with npm.
在 app.js
文件我使用
var jquery = require('jquery');
在html文件头中,我包含使用jQuery的javascript,我得到`jQuery没有定义'。
这是一个订单的量子还是我缺少一些东西?
In the html file header I included javascript that uses jQuery and I get `jQuery is not defined'. Is it a metter of order or am I missing something?
推荐答案
当您安装 jQuery
with npm
这是因为你想在你的服务器端使用 jQuery
应用程序(例如:您的 app.js
文件)。您仍然需要添加 jQuery
到您的网页:
When you are installing jQuery
with npm
it's because you want to use jQuery
on the server side of your application (Ex : in your app.js
file). You still need to add jQuery
to your web page like that :
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
如果要在客户端使用它。如果您使用 Jade
,请将脚本标签添加到模板中。
If you want to use it on the client side. If you are using Jade
, add the script tag to your template.
这篇关于如何在Express应用程序中使用带有npm的jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!