首页 > 解决方案 > 使用 Node 发送和接收 pdf 文件

问题描述

我正在使用 Express 使用 NodeJs 创建后端服务器。该项目的功能之一是发送和接收 PDF 文件。后端的其他路由发送和接收 JSON 文件,但我想创建一个发送和接收 PDF 文件的路由,我该怎么办?到目前为止我所拥有的:


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:
*/

在 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)
}

标签: javascriptnode.jsexpresspdf

解决方案


推荐阅读