После бесчисленных часов возни с загрузкой файлов с помощью моей настройки (ведьма довольно распространена) - Node.js, Express, Angular и MongoDB - я нашел то, что выглядит как самый простой способ сделать это: (мне нужно, чтобы страница не перезагружалась в форме Разместить)

установите эти модули:

npm install express-fileupload

npm install xlsx-to-json-lc - сохранить

npm install xls-to-json-lc - сохранить

а для углового добавить:

npm install ng-file-upload

в html добавьте форму:

‹form›
‹input type =” file ”ngf-select =” fileSelected ($ files); ” / ›
‹ input value = ”Загрузить!” ng-click = ”submit ();” / ›
‹/form›

в угловом контроллере добавить:

$ scope.fileSelected = function (files) {
if (files && files.length) {
$ scope.myFile = files [0];
}}

$ scope.submit = function () {
if ($ scope.myFile)
{
$ scope.upload ($ scope.myFile);
}
}

$ scope.upload = function (file) {
Upload.upload ({
url: '/ upload',
file: file
}). then (function (соответственно) {
console.log (resp.data.data)
});
};

в node app.js добавьте:

var fileUpload = require (‘express-fileupload’);

app.use (fileUpload ());

а затем выставить маршрут:

var xlstojson = require («xls-to-json-lc»);
var xlsxtojson = require («xlsx-to-json-lc»);

router.post (‘/ upload’, function (req, res) {

if (! req.files.file) {
res.send («Файлы не загружены.»);
return;
}

var sampleFile;
var exceltojson;

sampleFile = req.files.file;

sampleFile.mv ('./ uploads /' + req.files.file.name, function (err) {
if (err) {
console.log («eror save»);
}
else {
console.log («сохранено»);
if (req.files.file.name.split ('.') [req.files.file .name.split ('.'). length-1] === 'xlsx') {
exceltojson = xlsxtojson;
console.log («xlxs»);
} else {
exceltojson = xlstojson;
console.log («xls»);
}
попробуйте {
exceltojson ({
input: './uploads/ '+ req.files.file.name,
output: null, // поскольку нам не нужен output.json
lowerCaseHeaders: true
}, function (err, result) {< br /> if (err) {
return res.json ({error_code: 1, err_desc: err, data: null});
}
res.json ({error_code: 0, err_desc: null, data: result});
var fs = require ('fs');
попробуйте {
fs.unlinkSync ('./ uploads /' + req.files.file .name);
} catch (e) {
// ошибка при удалении файла
}

});
} catch (e) {
console.log («error»);
res.json ({error_code: 1, err_desc: «Corupted excel file»} );
}

}
});