Last active
August 19, 2022 19:01
-
-
Save zeluizr/7c398f7f39b98507e6ddb505d9b78a89 to your computer and use it in GitHub Desktop.
XML with Express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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