Skip to content
Advertisement

How to do an action after callback in node?

How to fire the final console.log AFTER the callback is finished.

var nodePandoc = require('node-pandoc');
var src, args;
 
src = 'Lesson.docx';
args = '-f docx -t markdown -o ./Lesson.md';

callback = function (err, result) {
  if (err) console.error('Oh No: ',err);
  return console.log("callback result:",result), result;
};

nodePandoc(src, args, callback);

console.log("Conversion finished, you can call function to move the file around"); 

Advertisement

Answer

The easiest way is to just log the final line from within the callback:

var nodePandoc = require('node-pandoc');
var src, args;
 
src = 'Lesson.docx';
args = '-f docx -t markdown -o ./Lesson.md';

callback = function (err, result) {
  if (err) return console.error('Oh No: ',err);
  console.log("callback result:",result);
  console.log("Conversion finished, you can call function to move the file around");
};

nodePandoc(src, args, callback);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement