Search code examples
node.jsxmlcurlcommand-linexmlhttprequest

How to execute curl commands from Node.js


My curl command sends XML data from an XML file, and the response is written to the specified path. How can I make this happen in Node.js?

cd C:/test/  && curl  localhost:9001 --data @ C:/test/Basic/SPND.xml -o  C:/test/Basic/Result.xml';

Solution

  • You can use something like this

    const { exec } = require("child_process");
    
    exec("ls -la", (error, stdout, stderr) => {
        if (error) {
            console.log(`error: ${error.message}`);
            return;
        }
        if (stderr) {
            console.log(`stderr: ${stderr}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
    });