return callback nodejs code example

Example 1: javascript getposts callback

// *** JS GetPosts Callback ***

    run.addEventListener('click', () => {
        window.lib.getPosts((error, articles) => {
          	return (error ? console.log(error) : console.log(articles));
            /* Alternate syntax
          	 if (error) {
                 console.log(error);
             }
             for (elem of articles) {
                 console.log(elem);
            }; // => console.log(articles); similarly works
            /*
        });
    })

Example 2: node js callback

function processData (callback) {
  fetchData(function (err, data) {
    if (err) {
      console.log("An error has occurred. Abort everything!");
      return callback(err);
    }
    data += 1;
    callback(null, data);
  });
}

processData(function (err, data) {
  if (err) {
      console.err(err);
  } else {
    console.log("Data: " + data);
  }
});