简体   繁体   English

如何使用Express(NodeJS)从服务器向客户端发送大量文件

[英]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.

相关问题 从服务器向客户端发送数据。 节点JS,快递 - Send data from server to client. NodeJS, Express 如何在Node.js中将数据从服务器发送到客户端? - How to send data from server to client in nodejs? 如何从后端(快递)在nodeJS中创建html文件并将其发送到客户端? - How to create and send html file to client in nodeJS from backend(express)? 我不知道如何在 nodejs express 服务器中存储来自 api 调用的 json 数据,并将其发送到反应本机客户端 - I do not know how to store json data from an api call within a nodejs express server, and send it to a react native client 如何使用websocket将json中的base64 url​​数据从javascript客户端发送到nodejs服务器? - How to send base64 url data using json from javascript client to nodejs server using websocket? 如何使用 Node.js express 从服务器向客户端发送实时响应 - How to send real time response from server to client using Node.js express 如何使用 Pusher 将用户的存款和取款详细信息从客户端发送到 Node.js(快递)服务器? - How to send deposit and withdraw details of user from client to Node.js (express) server using Pusher? 如何使用 Node.js express 从服务器向客户端发送实时 stream 响应 - How to send real time stream response from server to client using Node.js express 如何在Next js上将数据从快递服务器发送到客户端? - How to send data from express server to client on Next js? 尝试使用multer将文件从客户端(Angular)保存到服务器(Express) - Trying to save files to server (Express) from client (Angular) using multer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM