Use our APIs in your custom web application (Node.js/Express)

Learn how to seamlessly integrate our powerful workforce solutions into your Node.js web application.

If you're building a web application using Node.js, you can easily incorporate our APIs into your backend to access the powerful capabilities of our workforce solutions. This guide will walk you through the process of integrating the Skills API into your Node.js web application using the Express framework.

Prerequisites

Before you start, ensure that you have the following prerequisites in place:

  • Node.js installed on your development machine
  • A basic understanding of Node.js and Express framework

Setting up the Project

  1. Create a new directory for your project and navigate to it in the terminal.

  2. Initialize a new Node.js project by running the following command:

    npm init -y
    
  3. Install the required dependencies, including Express and axios (a popular HTTP client library for Node.js), by running the following command:

    npm install express axios
    
  4. Create a new file named app.js and open it in your preferred code editor.

Creating the Express Server

In app.js, start by importing the necessary modules and setting up the Express server:

const express = require('express');
const axios = require('axios');

const app = express();
const PORT = process.env.PORT || 3000;

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

Defining the Skills API Route

Next, define a route to fetch skills data from the Skills API. In this example, we'll create a /skills endpoint that returns a list of skills:

app.get('/skills', async (req, res) => {
  try {
    const response = await axios.get('https://example.com/di/v1/skills');
    const skills = response.data.skills;

    res.json({ skills });
  } catch (error) {
    console.error('Error retrieving skills:', error);
    res.status(500).json({ error: 'Failed to retrieve skills' });
  }
});

In the above code, we use the axios library to send a GET request to the Skills API endpoint /di/v1/skills. Upon successful retrieval of the skills data, we extract the skills array from the response and send it back as a JSON response to the client. If an error occurs, we log the error and send an appropriate error response.

Starting the Server

Finally, add the following code at the end of app.js to start the server:

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

Testing the API

To test the /skills endpoint, start your Node.js server by running the following command in the terminal:

node app.js

Open a web browser and navigate to http://localhost:3000/skills. You should see a JSON response containing the list of skills fetched from the Skills API.

Remember to refer to our API documentation for detailed information on available endpoints, request parameters, and response formats. If you encounter any issues or have questions, our support team is always ready to assist you. Happy coding!