Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Node.js exec to build Marp markdowns doesn't work

I wrote this simple node.js script to build Marp markdown and convert them to PDF. But it doesn't do anything and doesn't terminate. I added a console.log("test") at the end I see that node.js doesn't wait for all the command executions to finish but exec also doesn't run the Marp build command.

If I run the "cmd" string from the terminal it all works. I think something is wrong with the way I use exec

var glob = require("glob");
var cp = require("child_process");

glob("lab*/*.marp.md", {}, function (err, files) {
  files.forEach((file) => {
    var destination = file.replace(".md", "");
    var cmd = `marp ${file} --allow-local-files --pdf -o ${destination}.pdf`;
    var dir = cp.exec(cmd, (err, stdout, stderr) => {
      if (err) {
        console.log("node couldn't execute the command");
        return;
      }

      // the *entire* stdout and stderr (buffered)
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });

    dir.on("exit", function (code) {
      // exit code is code
      console.log(`finished building: ${file}`);
    });
  });
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can try the execSync() function It'll solve the issue

var glob = require("glob");
var cp = require("child_process");

glob("lab*/*.marp.md", {}, function (err, files) {
  files.forEach((file) => {
    var destination = file.replace(".md", "");
    var cmd = `marp ${file} --allow-local-files --pdf -o ${destination}.pdf`;

    var dir = cp.execSync(cmd, (err, stdout, stderr) => {
      if (err) {
        console.log("node couldn't execute the command");
        return;
      }

      // the *entire* stdout and stderr (buffered)
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });

    dir.on("exit", function (code) {
      // exit code is code
      console.log(`finished building: ${file}`);
    });
  });
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!