Node.js Project to Find Facebook UserId From Username Using facebook-id-of Library in Javascript

You are currently viewing Node.js Project to Find Facebook UserId From Username Using facebook-id-of Library in Javascript

 

Welcome folks today in this blog post we will be fetching or extracting facebook user id from username in javascript. All the source code of the application is given below.

 

 

Get Started

 

 

In order to get started we need to install this library get-facebook-id by using the npm command a shown below

 

npm i get-facebook-id

 

Now after installing this library we need to create index.js file and copy paste the following code

 

index.js

 

 

const facebookIdOf = require('facebook-id-of');

// using callback
facebookIdOf('an_user', function (err, facebookId) {
  if (err) return console.error(err);
  console.log(facebookId);
});

// using promise
facebookIdOf('an_user')
  .then((facebookId) => {
    console.log(facebookId);
  })
  .catch((err) => {
    console.error(err);
  });

// using async/await
async function () {
  try {
      const facebookId = await facebookIdOf('an_user');
      console.log(facebookId);
  } catch (err) {
      console.error(err);
  }
}

 

 

 

Getting started

 

 

CLI usage

 

 

 

npm i -g facebook-id-of

 

 

Leave a Reply