Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Express中包含库或外部样式表_Javascript_Html_Node.js_Express - Fatal编程技术网

Javascript 在Express中包含库或外部样式表

Javascript 在Express中包含库或外部样式表,javascript,html,node.js,express,Javascript,Html,Node.js,Express,我正在节点服务器上使用express framework构建一个todo应用程序……我有一个index.ejs文件作为我的应用程序的起点,当我尝试将jquery文件包含为 <script src="jquery.min.js" type="text/javascript"></script> 当我在chrome浏览器中看到网络时,我的应用程序无法加载它https://localhost:3000/jquery.min.js https://localhost:300

我正在节点服务器上使用express framework构建一个todo应用程序……我有一个index.ejs文件作为我的应用程序的起点,当我尝试将jquery文件包含为

<script src="jquery.min.js" type="text/javascript"></script>

当我在chrome浏览器中看到网络时,我的应用程序无法加载它https://localhost:3000/jquery.min.js https://localhost:3000/jquery.min.js 如何加载文件


PS:我习惯于通过cloud.google.com将url放在src标记中加载脚本,但我希望我的应用程序通过这种方法加载得更快

您应该为静态文件创建一个./public文件夹

将此行添加到app.js中,优先于所有路线:

  app.use(express.static(path.join(__dirname, 'public')));
然后在index.ejs中使用这个:

<script src="/jquery.min.js"></script>

您应该为静态文件创建一个./public文件夹

将此行添加到app.js中,优先于所有路线:

  app.use(express.static(path.join(__dirname, 'public')));
然后在index.ejs中使用这个:

<script src="/jquery.min.js"></script>


My code我在src/configuration.coffee&My index.ejs中添加的行在src/views中…这会给我一个错误“Reference error:path not defined”(参考错误:路径未定义),您必须
require
path模块<代码>变量路径=要求(“路径”)
路径
模块记录在我的代码中,我在src/configuration.coffee&My index.ejs中添加的行在src/views中…这会给我一个错误“参考错误:路径未定义”,您必须
要求
路径
模块<代码>变量路径=要求(“路径”)
路径
模块记录在案