我想获得上一页的网址.我找到了很多答案,但我找不到任何适用于浏览器后退按钮的东西.我使用了document.referrer,但它也不适用于后退按钮.谁能帮我??
我是node和mongoDB的新手.我正在使用nodeJS,express和mongoDB开发一个应用程序.我想从文件输入字段读取csv/xlsx文件,并使用mongoose将其存储在mongoDB中.我遇到了困难.我在前端使用angularjs.谁能给我建议我应该通过什么程序?具体代码将是很有帮助的.
我使用busboy模块将文件存储在特定文件夹中.这是我的代码
在路线:
router.post('/fileupload', function (req, res) {
var fstream;
req.pipe(req.busboy);
console.log(req.pipe);
console.log(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
console.log("Uploading: " + filename);
fstream = fs.createWriteStream('./files/' + filename);
file.pipe(fstream);
fstream.on('close', function () {
res.redirect('back');
});
});
});
Run Code Online (Sandbox Code Playgroud)
和我的前端:
<form method="post" action="/fileupload" enctype="multipart/form-data">
<input type="file" id="file" name="file">
<button type="submit">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
到目前为止没有错误.现在我只想将这些文件存储在数据库中.接下来我该怎么办?
我试图将json数据转换为Xlsx文件并将其保存在文件夹中.我一直在尝试使用icg-json-to-xlsx模块,但到目前为止我一直无法使用它.我的代码看起来像这样:
jsonXlsx = require('icg-json-to-xlsx');
filename = path.join('./files', "output.xlsx");
outputFile = jsonXlsx(filename, result) //result contains json data
console.log(outputFile);
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误
outputFile = jsonXlsx(filename, result)
^
TypeError: Property 'jsonXlsx' of object # is not a function
Run Code Online (Sandbox Code Playgroud)
从mongodb获取数据:在路由中:
router.get('/', function(req, res, next) {
fileController.getAll(function(err, result){
if(err){
res.send(500,err);
}
// res.json(result);
var data = result;
Run Code Online (Sandbox Code Playgroud)
在控制器中:
FileController.prototype.getAll = function(callback){
File.find( {}, {_id: false, id: true, name: true, status: true}, function(err, file){
if(err) {
return callback(err);
} else {
if (!file) {
return callback('file not found'); …Run Code Online (Sandbox Code Playgroud)