[英]How to send a lot of files from server to client using express (NodeJS)
I'm trying to send files from NodeJS server to clients. 我正在尝试将文件从NodeJS服务器发送到客户端。 Many images, css files, js files. 许多图片,css文件,js文件。 For a few files I use 我用了一些文件
app.get('/js/client.js', function (req, res) {
res.sendFile(path.join(__dirname, '/', 'client.js'));
});
The path is var path = require('path');
路径是var path = require('path');
So, if I use this construction for every file I want to send, this part of the code will be huge. 因此,如果我对要发送的每个文件使用此构造,那么这部分代码将非常庞大。 How can I simplify it? 如何简化呢?
如果要提供静态内容,请将所有内容放入公用文件夹中,将使用express自动提供内容。
app.use(express.static( __dirname + "/public"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.