Failed to load latest commit information.
lib Fix the ugly ? and & at the end if no params nor access token Jun 3, 2016
test Fix the ugly ? and & at the end if no params nor access token Jun 3, 2016
.gitignore Bugfix, make so that Facebook class can use for accessing public data… Jun 7, 2014
.travis.yml No sudo and, drop 0.8 and adding stable Sep 19, 2015
LICENSE More API version update in doc Mar 15, 2015
index.js Adding export of main lib file Jul 25, 2012
package.json Use nock for mocking response May 13, 2016

Facebook nodejs

A simple module for querying Facebook graph api and fql

Usage example

var express = require('express');
var fbgraph = require('fbgraphapi');
var app = express();
var http = require('http');
var server = http.createServer(app);

app.use(express.session({secret : "SECRET"}));
app.use(fbgraph.auth( {
		appId : "...",
		appSecret : "...",
		redirectUri : "",
		apiVersion: "v2.2"

app.get('/login', function(req, res) {
	console.log('Start login');
	fbgraph.redirectLoginForm(req, res);	

app.get('/', function(req, res) {
	if (!req.hasOwnProperty('facebook')) {
		console.log('You are not logged in');
		return res.redirect('/login');
	/* See for more */
	req.facebook.graph('/me', function(err, me) {
	req.facebook.graph('/me?fields=id,name', function(err, me) {
	});, me) {
	// /me/likes, likes) {
	res.end("Check console output");


Or if have a valid access token for instance from javascript fb connect

var fb = new fbgraph.Facebook(accessToken, 'v2.2');, me) {

Or do stuff on behalf of the app or user with granted permissions

var fb = new fbgraph.Facebook(fbgraph.getAppId() + '|' + fbgraph.getAppSecret());'/{user-id}/feed', {message: 'Hello world'},function(err, res) {
	console.log(err, res);

Facebook API reference

Visit the links bellow for API documentation of Facebook API



config is an object with those properties

  • appId Facebook application Id
  • appSecret Secret hash key generated by Facebook
  • redirectUri The url to redirect to when user logged in.
  • apiVersion Which api version to use, example v2.2
  • scope Permissions/scope that your application asks for, optional and default empty.
  • skipUrlPatterns Array of patterns which to not apply authentication on. They can be regexp or string. If string a regexp will be created with wildcard appending at the end. If you want an exact url make sure specify regexp.

authenticate(req, res, next)

This method is returned when calling auth() above. When loggin is successfull it will assign a Facebook instance to req (see example above).

redirectLoginForm(req, res)

This method will redirect user to Facebook login form.

destroySession(req, res, clearCookie)

This method is for logging out user or for any reason want to clear user's logged-in info


return app id, set via auth()


return app secret, set via auth()


Facebook(accessToken, apiVersion)

Usage: if have a valid accessToken for instance from js login

var fb = new Facebook(accessToken, 'v2.2');, me) {


This class uses internally to create object my (property in Facebook). This object wrap the me-object. Each connection type is a method. This means that you can make a call like, friends) {

// OR for checkins, checkins) {

Supported connection types are:

  • friends
  • feed
  • likes
  • movies
  • music
  • books
  • albums
  • notes
  • permissions
  • photos
  • videos
  • events
  • groups
  • checkins
  • locations

If you can not find a connection that Facebook has but not here you can use connection-method'{connection type}', function(err, result) {