I am trying to send data from my html for node.js Express using a post method.
Using this code on my html file:
function readfile() {
var data = {};
data.path = '/home/test/pgadmin.txt';
data.ext = '.txt';
console.log(data);
$.ajax({
url: '/read_file',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(data),
success: function(data) {
console.log(data);
}
});
}
And this is the code that I'm using on server side.
var express = require('express')
var path = require('path')
var app = express()
app.post('/read_file', function(req, res) {
console.log(req.data.path) //?
console.log(req.data.ext) //?
//I dont know how to get the values of my data: here
})
Is there some way to get those data values without using bodyparser?