Node.js icon

Node.js Quick Start Guide

Get started with FacePing's face recognition API using Node.js

Prerequisites

Installation

First, install the required dependencies:

npm install node-fetch form-data

Step 1: Create a Face Group

Groups help organize your face vectors. Here's how to create one:

const fetch = require('node-fetch');

async function createGroup(groupName) {
    const response = await fetch(`https://api.faceping.ai/groups/${groupName}`, {
        method: 'POST'
    });
    return await response.json();
}

// Usage
createGroup('my-group')
    .then(result => console.log(result))
    .catch(error => console.error(error));

Step 2: Store Face Images

After creating a group, you can store face images as vectors:

const fs = require('fs');
const FormData = require('form-data');

async function storeFace(groupName, imagePath) {
    const formData = new FormData();
    formData.append('image', fs.createReadStream(imagePath));

    const response = await fetch(`https://api.faceping.ai/groups/${groupName}/faces`, {
        method: 'POST',
        body: formData
    });
    return await response.json();
}

// Usage
storeFace('my-group', './face.jpg')
    .then(result => console.log(result))
    .catch(error => console.error(error));

Step 3: Search for Similar Faces

Once you have stored faces, you can search for similar ones:

async function searchFaces(groupName, imagePath) {
    const formData = new FormData();
    formData.append('image', fs.createReadStream(imagePath));

    const response = await fetch(`https://api.faceping.ai/groups/${groupName}/search`, {
        method: 'POST',
        body: formData
    });
    return await response.json();
}

// Usage
searchFaces('my-group', './search-face.jpg')
    .then(results => console.log(results))
    .catch(error => console.error(error));

Security Notes

  • Images are immediately discarded after vector conversion
  • Face vectors cannot be reverse-engineered into images
  • Always use HTTPS for all API calls
  • Keep your API keys in environment variables

Ready to get started?

Take a look at the API documentation
API docs