I can't find documentation that can help me or some examples. I created a model (json object) for my data base (mongodb) then I created a form in the client side (react) to generate my data. I want to know how can I take this data and convert it into an XML file. All I know is JSon object can be converted in xml file I tried some things but they don't work.
This my model:
const mongoose = require('mongoose');
const fileSchema = mongoose.Schema({
title: {
type: String,
trim: true
},
file_path: {
type: String,
required: true
},
file_mimetype: {
type: String,
required: true
}
}, {
timestamps: true
});
const File = mongoose.model('File', fileSchema);
module.exports = File;
and this is my server.js
require("dotenv").config({ path: "./config.env" });
const express = require("express");
const app = express();
const errorHandler = require("./middleware/error");
const path = require('path');
const fileRoute = require('./routes/file');
const Cors = require('Cors');
const mongoose = require('mongoose')
require('dotenv').config();
app.use(Cors());
// Connect DB
const PORT = process.env.PORT || 5000;
const url = process.env.MONGO_URL;
mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then(() => {
console.log("Server up and running!")
})
app.use(express.json());
app.get("/", (req, res, next) => {
res.send("Api running");
});
// Connecting Routes
app.use("/api/auth", require("./routes/auth"));
app.use("/api/private", require("./routes/private"));
//aploadfile
app.use(express.static(path.join(__dirname, '..', 'build')));
app.use(fileRoute);
app.get("/upload", (req, res) => {
res.sendFile(path.join(__dirname, '..', 'build', 'index.html'));
});
// Error Handler Middleware
app.use(errorHandler);
const server = app.listen(PORT, () =>
console.log(`Sever running on port ${PORT}`)
);
process.on("unhandledRejection", (err, promise) => {
console.log(`Logged Error: ${err.message}`);
server.close(() => process.exit(1));
});