Home > Net >  How to do an action after callback in node?
How to do an action after callback in node?

Time:06-04

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"); 

CodePudding user response:

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);
  • Related