npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lekko/node-server-sdk

v0.2.0

Published

Lekko Node Server SDK

Downloads

56

Readme

Lekko Node Server SDK

The Lekko Server SDK for Node.js

Getting Started

Installation

You can install @lekko/node-server-sdk using NPM or Yarn.

@lekko/node-server-sdk depends on source code generated by Buf which is hosted on their NPM registry. Prior to adding the Lekko SDK, configure your package manager to use Buf's NPM registry for @buf scoped packages.

Note

Due to the dependency on Buf's source code generation, we currently do not support installing with Yarn versions older than v2 (a.k.a. Yarn Classic). Please refer to Buf's docs here for more information.

NPM

The following command updates your .npmrc file.

npm config set @buf:registry https://buf.build/gen/npm/v1

Yarn

You must edit your .yarnrc.yml file to include the following scope:

npmScopes:
  buf:
    npmRegistryServer: https://buf.build/gen/npm/v1

Then, you can add the package to your project by running npm install @lekko/node-server-sdk or yarn add @lekko/node-server-sdk.

Usage

Initializing a cached Lekko client

Creates a client that fetches configs from Lekko backend and caches them in memory. Configs are kept up to date via polling.

const lekko = require("@lekko/node-server-sdk");

const client = await lekko.initCachedAPIClient({
    apiKey: <API_KEY>,
    repositoryOwner: <REPOSITORY_OWNER>,
    repositoryName: <REPOSITORY_NAME>,
});

const context = new lekko.ClientContext().setString("my_context_key", "my_context_value");
const stringConfig = await client.getString("my_namespace", "my_config", context);
console.log(stringConfig);

Initializing a cached Lekko client in git mode

Creates a client that reads configs from a git repository on disk and caches them in memory. Configs are kept up to date via a file watcher.

const lekko = require("@lekko/node-server-sdk");

const client = await lekko.initCachedGitClient({
    apiKey: <API_KEY>,
    repositoryOwner: <REPOSITORY_OWNER>,
    repositoryName: <REPOSITORY_NAME>,
    path: 'path/to/config/repo',
});

const context = new lekko.ClientContext().setString("my_context_key", "my_context_value");
const boolConfig = await client.getBool("default", "example", context);
console.log(boolConfig);

Note on using ES modules

In a traditional Node.js environment, you initialize the Lekko client using CommonJS modules:

const lekko = require("@lekko/node-server-sdk");

Modern versions of Node also support ES (ECMAScript) modules, using the import syntax:

import * as lekko from "@lekko/node-server-sdk"; // or
import { initAPIClient, initSidecarClient } from "@lekko/node-server-sdk";

The SDK is packaged as a CommonJS module. To use it as an ES module like the above example, add the following to your package.json:

{
  "type": "module"
}

To learn more about the Node.js module system, refer to their docs here.

Example

See: https://github.com/lekkodev/node-server-sdk/tree/main/example-ts