Home > Software engineering >  How to send xml file from Pug to Node JS
How to send xml file from Pug to Node JS

Time:07-04

Hello I am building an app in which you upload an xml file and send it to an api. I am using Pug and NodeJS with Express. I am new to this. I created in pug the upload and send button and a function to receive on node the file. The frontend and backend are running on the same port. How can I send the xml file to the backend to read it and send it to the api ?

This is my code:

Pug:

    doctype html
html(lang='en')
 head
   title Transport
 body
   h3 Upload XML:
   form(method='post', enctype='multipart/form-data' action='/upload')
    input(type='file', name='xml')
    br
    input(type='submit', name='xml', value='Upload XML')

app.js file:

const express = require('express')
const app = express()
app.set('view engine', 'pug')
app.set('views', './src/views')
app.get('/', (req,res) => {
res.render('index')
});

app.get('/upload', (req,res) => {
    
})

app.listen(3000, () => console.log("Listening on port 3000"))

It is my first app built with node and pug and this is why I am asking this easy question.

CodePudding user response:

your method is mismatch.you should change your get method in app.js file to post method

CodePudding user response:

change GET to POST and then your files will be in req.files property

  • Related