我尝试运行服务器,但收到此错误
var express = require('express');
var bodyParser = require('body-parser');
var fs = require('fs');
var http = require('http');
cors = require('cors');
var app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/', function(req, res) {
let body = '';
let dir = './example-dir';
req.on('data', function(data) {
body += data;
});
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
req.on('end', function() {
fs.writeFile(dir + '/result.xml', body, function(err) {
if (err) {
return console.log(err);
}
res.send('You just created new xml file!')
});
});
})
const port = process.env.PORT || 3600;
app.set('port', port);
var server = http.createServer(app)
server = app.listen(port, () => {
console.log('Connected to port ' + port )
})
我使用fs模块从角度写入数据,并保存在后端example-dir中的xml文件中 我想从angular中获取xml并在后端的文件中发布