0

i'm using Express to create a backend server using NodeJs. One of the functionalities of the project is to send and receive PDF files. The other routes of the backend send and receive JSON files but i want to create a route for send and receive PDF files, what can i do? What i have until now:


const express = require('express')
const app = express()
const db = require('./config/db')
const consign = require('consign')
const consts = require('./util/constants')
//const routes = require('./config/routes')
consign()
    .include('./src/config/middlewares.js')
    .then('./src/api')
    .then('./src/config/routes.js') // my routes file
    .into(app)

app.db = db // database using knex

app.listen(consts.server_port,()=>{
    //console.log('Backend executando...')
    console.log(`Backend executing at port: ${consts.server_port}`)
})
app.get('/',(req,res)=>{
    res.status(200).send('Primary endpoint')
})
/* basically at routes.js file i'm handling http routes that manages JSON objects such as this one below:
*/

At routes.js:

// intercept http routes and pass specific funtion for handling them

module.exports =app=>{
    app.route('/products')// regular JSON objects
        .post(app.src.api.itensVenda.saveItem)
        .get(app.src.api.itensVenda.getItems)
        .put(app.src.api.itensVenda.toggleItemVisibility)


    app.route('/articles') 
       .get(app.src.api.articles.getArticle)
       .post(app.src.api.articles.saveArticle)
// the route above is the one that i want to use for sending and receive PDF files

    app.route('/info')// ordinary JSON objects
        .post(app.src.api.info.saveInfo)
        .get(app.src.api.info.getInfo)
}

0 Answers0