Skip to content

Instantly share code, notes, and snippets.

@zeluizr
Last active August 19, 2022 19:01
Show Gist options
  • Save zeluizr/7c398f7f39b98507e6ddb505d9b78a89 to your computer and use it in GitHub Desktop.
Save zeluizr/7c398f7f39b98507e6ddb505d9b78a89 to your computer and use it in GitHub Desktop.
XML with Express
const express = require('express')
const app = express()
const xml = require('xml')
app.get('/users', (req, res, next) => {
let xml = `<?xml version="1.0" encoding="UTF-8"?>`
xml += `<user>`
for (let i = 0; i < 99; i++) {
xml += `
<customer>
<firstName>Henry</firstName>
<lastName>William</lastName>
</customer>`
}
xml += `</user>`
res.header('Content-Type', 'application/xml')
res.status(200).send(xml)
})
app.listen(4000, (res) => {
console.log('Server started on port : 5000')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment