Hormis Lona
Hormis Lona

Reputation: 523

How can i return an XML file corresponding to a URL request in node.js?

I have a URL like www.xxx.com/get-xml-content. I want to send an XML file as a response to this URL request.

<?xml version="1.0" encoding="UTF-8"?>
   <response>
      <playtext>I lov u</playtext>
   </response>

The XML I created will looks like above. I want to send this XML as a response to the given URL. How can it be possible in Node.js?

Upvotes: 1

Views: 310

Answers (1)

Thalaivar
Thalaivar

Reputation: 23632

There are lots of libraries which can help you serve a xml as response. Here is one, which can help you

https://www.npmjs.com/package/xml

var xml = require('xml');

response.set('Content-Type', 'text/xml');
response.send(xml(yourobj));

Upvotes: 1

Related Questions