The usual form on the client:
<form method="post" enctype="multipart/form-data"> <input type="file" name="file"> <button type="submit" name="button">Отправить файл</button> </form> How to handle a file without using express / koa on the server and without AJAX on the client? The main thing that I can not understand is how to get the file name. The file data itself is normal - the file is successfully saved on the server. Using AJAX, everything is sent without problems - both the file itself and its name (we ask ourselves), but it’s interesting how to do this using just HTML5 on the client (as I understand, multipart / form-data was created specifically for this) and processing on the node.
switch (req.method) { case 'POST': // вместо filename сейчас заглушка из рандомного названия receiveFile(__dirname + '/files/' + 'filename', req, res); break; /* .... */ } function receiveFile(filePath, req, res) { let file = fs.createWriteStream(filePath, {flags: 'wx'}); req.pipe(file); /* .... */ }