[英]Why am I able to import my JS in different ways?
My folder structure :我的文件夹结构:
--public
----frontend.js
--views
----fontend.ejs
frontend.js inside public folder and frontend.ejs inside views folder.公共文件夹中的frontend.js 和视图文件夹中的frontend.ejs。
In the html / ejs file I linked the javascript (frontend.js) like this在 html/ejs 文件中,我像这样链接了 javascript (frontend.js)
<script src="/frontend.js"></script>
Instead of this而不是这个
<script src="../public/frontend.js"></script>
and it still works , why?它仍然有效,为什么?
Check your app.js
in your express project, express.static
is getting used to serve public
folder for /
by default.检查您的 express 项目中的
app.js
, express.static
默认用于为/
提供public
文件夹。 . .
Exact syntax doing this -这样做的确切语法 -
app.use(express.static(path.join(__dirname, 'public')));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.