0
我正在使用node.js將文件索引到elasticsearch中。我正在嘗試將輸入作爲jmeter的文件輸入?使用req.file我試着讀取文件,但它給輸出爲未定義。誰能指定更好的解決方案?如何將jmeter文件讀入本地系統?
var http = require('http');
var express = require('express');
var app = express();
var CircularJSON = require('circular-json');
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: '10.96.82.98:9200',
log: 'trace'
});
http.createServer(app).listen(1000);
//indexing a document
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.post('/post/:index/:type/:id/', function(req, res){
var fs = require("fs");
fs.writeFile('inpu.file',req.file);
client.index({
index: req.params.index,
type: req.params.type,
id: req.params.id,
body:JSON.parse(fs.readFileSync(__dirname +'/inpu.file'))
},function (error, response) {
console.log(response);
res.send(response);
});
});
我使用這個代碼
任何這方面的運氣? – Val