body` of form in my database but it returns empty object even with express.json() and express.urlencoded()
i tried it with body-parser too and even log it in console but it is the same
this is main index:
const app = express();
let port = 3000;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default class Application {
constructor() {
this.setConfigServer();
this.configDatabase();
this.setConfig();
this.setRoutes();
}
setConfigServer() {
app.listen(port, () => {
console.log(`server is listening to port ${port}`);
console.log("http://localhost:3000");
});
}
async configDatabase() {
await mongoose.connect("mongodb://localhost:27017/test");
}
setConfig() {
app.use(express.static(__dirname + "/public"));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "/views"));
app.use(expressEjsLayout);
app.set("layout extractScripts", true);
app.set("layout extractStyle", true);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
}
setRoutes() {
app.use(routes.router);
}
}
router file ===>
const router = express.Router();
const SignInController = new signInController()
router.get("/register",SignInController.getForm)
router.post("/register",(req,res)=>{
res.setHeader("Content-Type", 'application/json');
req.header("Content-Type", 'application/json');
res.write("you posted:n");
res.end(JSON.stringify(req.body));
})
export default{router}