// docx header and footer demo
const docx = require('docx@6.0.1');
const express = require("@runkit/runkit/express-endpoint/1.0.0");
const app = express(exports);
const { Document, Footer, Header, Packer, Paragraph } = docx;
app.get("/", async (req, res) => {
const doc = new Document({
sections: [{
headers: {
default: new Header({
children: [new Paragraph("Header text")],
}),
},
footers: {
default: new Footer({
children: [new Paragraph("Footer text")],
}),
},
children: [new Paragraph("Hello World")],
}],
});
const b64string = await Packer.toBase64String(doc);
res.setHeader('Content-Disposition', 'attachment; filename=My Document.docx');
res.send(Buffer.from(b64string, 'base64'));
});