@datanest-earth/nodejs-client
TypeScript icon, indicating that this package has built-in type declarations

0.4.6 • Public • Published

Datanest API Client for Node.js

This is a Node JS implementation of datanest.earth's REST API client. You should use this lightweight package to easily start using the API.

If you are not using Node.js you can use this package as an implementation example.

Please see the Datanest API documentation for more information. If you need help please contact hello@datanest.earth for technical support.

Obtaining API Keys

Your Datanest Account Manager can generate API keys, from the Company Settings page, API Keys section.

Show Screenshot

API Key management section

Requirements

If you wish to use this Node package, you will need to have Node installed on your machine. This package should work with both Bun and Deno runtime alternatives (unverified)

We recommend the latest stable version of Node.

  • Tested on Node v20.8.0
Minimum requirements
  • Fetch API is required, available in Node v18.0+ (unverified)

node-fetch may allow for earlier versions

Installation for Node projects

Install from NPM using your preferred package manager.

npm install --save @datanest-earth/nodejs-client
Alternatives
pnpm add @datanest-earth/nodejs-client
bun add @datanest-earth/nodejs-client

Authentication

Datanest's API uses API keys to authenticate requests along with a HMAC signature (see docs) (see implementation example.) The signature may be tricky to implement, so we recommend using this package to get started.

Full REST API Documentation

Getting Started with Node.js

The client will automatically look for env variables to get the API key and secret. You can use the dotenv package to parse a .env file.

Place your API key in a .env

DATANEST_API_KEY=your-api-key
DATANEST_API_SECRET=your-api-secret

Simply instantiate DatanestClient

import DatanestClient from '@datanest-earth/nodejs-client';
import dotenv from 'dotenv';

// Load .env
dotenv.config();

const client = new DatanestClient();
Alternatively use the constructor to pass the API key and secret.
import DatanestClient from '@datanest-earth/nodejs-client';

const client = new DatanestClient('your-api-key', 'your-api-secret');
Require for CommonJS projects
const { DatanestClient, projects } = require("@datanest-earth/nodejs-client");

Make GET, POST, PATCH, PUT, DELETE requests

The client exposes the following methods to make requests to the API.

client.get(path, params?: Record<string, any>, optionalFetchOptions);
client.post(path, params?: Record<string, any>, optionalFetchOptions);
client.patch(path, params?: Record<string, any>, optionalFetchOptions);
client.put(path, params?: Record<string, any>, optionalFetchOptions);
client.delete(path, params?: Record<string, any>, optionalFetchOptions);

The underlying Fetch API is used, you can pass in any valid Fetch options as the third argument. For example, to add a custom header.

See Fetch API "options" docs

Example
import DatanestClient from '@datanest-earth/nodejs-client';
import dotenv from 'dotenv';

// Load .env
dotenv.config();

async function listProjects() {
  const client = new DatanestClient();
    client.setClientId("Company A Version 1");
    const response = await client.get('v1/projects');
    const projects = await response.json();
    console.log(projects);
}

listProjects();

Node API Endpoints and Types

This package includes endpoints with type definitions.

Function & Type Definitions:

You can also see the TypeScript source code

Example
import DatanestClient, { projects as projectEndpoints } from '@datanest-earth/nodejs-client';
import dotenv from 'dotenv';

// Load .env
dotenv.config();

async function listProjects() {
  const client = new DatanestClient();
  client.setClientId("Company A Version 1");
  const page = 1;
  const projects = await projectEndpoints.listProjects(client, page);
  console.log(projects);
}

listProjects();

Testing

You can override the default API endpoint by setting the DATANEST_API_BASE_URL environment variable.

DATANEST_API_BASE_URL=https://app.datanest.earth/api
Alternatively, you may set the base url from your code
import DatanestClient from '@datanest-earth/nodejs-client';

const client = new DatanestClient();
client.setBaseUrl('https://app.datanest.earth/api');

Package Sidebar

Install

npm i @datanest-earth/nodejs-client

Weekly Downloads

6

Version

0.4.6

License

ISC

Unpacked Size

120 kB

Total Files

13

Last publish

Collaborators

  • datanest-earth