New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-pexels

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pexels

Node client for https://www.pexels.com API

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
128
decreased by-28.49%
Maintainers
1
Weekly downloads
 
Created
Source

node-pexels

Node unofiicial client for https://www.pexels.com API. Typescript definitions included.

Build Status Coverage Status

Simple api client for Pexels powered by got package.

Check out Pexels API for API usage rules and key request.

Requirements

Node 10+

Changelog

v 1.0.0

Security updates. Removed es5 support in lib.

v 0.0.5

Fixes, deps update, etc.

v 0.0.4

Added retrieving single photo method (#1)

v 0.0.3

Some fixes in inner logic and interfaces. Added methods args validation. Some fixes in doc.

v 0.0.2

Some fixes in schema and ts definitions.

v 0.0.1

Hello, world! First version of package.

Usage

const Client = require('node-pexels').Client;
const fs = require('fs');

const client = new Client('your-api-key');

client.search('people', 5, 1)
    .then((results) => {
        // Do something with results
        console.log(results);
        if (results.photos.length > 0) {
            const photo = results.photos[0];
            const source = 'medium';

            return client.fetch(photo, source)
        } else {
            throw new Error('no results found');
        }
    })
    .then((file) => {
        return new Promise(
            (reject, resolve) => {
                fs.writeFile(
                    `./img.${file.format}`,
                    file.data,
                    (err) => {
                        if (err) {
                            reject(err);
                        }
                        resolve();
                    }
                );
            }
        );
    })
    .catch((error) => {
        // Something bad happened
        console.error(error);
    });

Docs

Client

constructor(apiKey: string)

Creates new API client instance.

search(query: string, perPage?: number, page?: number): Promise<IPexelsResponse>

Search request by provided query.

photo(id: number): Promise<IPexelsImage>;

Search photo by provided id.

popular(perPage?: number, page?: number): Promise<IPexelsResponse>

Popular photos request.

fetch(photo: IPexelsImage, src: TPexelsImageSource): Promise<IImageData>

Fetch a photo file from the selected source.

IPexelsResponse, IPexelsImage

Responses from pexels api.

IImageData

Object containing an image buffer, and format.

You can find schemas here and response example on the Pexels API page.

FAQ

Does client use http or https?

Client use https. You can use http (if you really want to) by modifying endpoint property of Client function.

Keywords

FAQs

Package last updated on 06 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc