random-pexels-image

Simple Node.js application that provides an endpoint to search Pexels and return a randomly selected image. It allows hotlinking images by directly returning the image data.

A Node.js application that provides an endpoint to search Pexels and return a randomly selected image, allowing hotlinking by directly returning the image data. It fetches images from the Pexels API based on query parameters such as size, keyword, and orientation, and when no keyword is supplied it picks a random word from a list of 300. It is intended for web applications or services that need to dynamically fetch and display Pexels images without storing them locally. The server reads a Pexels API key and port from a .env file and exposes a /search-image GET endpoint.

Installation

  1. Clone the repository

    git clone https://github.com/jparkerweb/pexels-image-search-api.git
    cd pexels-image-search-api
  2. Install the dependencies

    npm install
  3. Create a .env file in the root directory and add your Pexels API key and server port

    PEXELS_API_KEY=your_pexels_api_key
    PORT=8000
  4. Optionally adjust the random-words.json file with random words if a keyword is not submited with each search request