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

remote-model

v2.0.0

Published

A fetcher for an externally hosted config file, that is released on a different cadence to your service

Downloads

5

Readme

Remote Model

A fetcher for an externally hosted config file, that is released on a different cadence to your service

Written in javascript, for node based projects.

Features

  • Auto update after n milliseconds (default, 5 minutes)
  • Synchronous call caching
  • Hot caching
  • Can use any async method inplace of the network operation

Benefits of this approach - multiple callers can request data, but only one network call will be made. This ensures that all parts of your application receive the latest data at the same time.

Quickstart

Install:

npm install --save remote-model

Default behaviour with URL

HTTPS Usage, e.g. download file from remote host:

import remoteModel from 'remote-model'

const myModel = remoteModel({
  url: 'https://raw.githubusercontent.com/connected-web/remote-test/master/info.json',
  updateIntervalMs: 10 * 60 * 1000 // 10 minutes
})

myModel.fetch().then((data) => {
  console.log('[My Model]', data)
})

myModel.notify((data) => {
  console.log('[My Model] Updated', data)
})

Using a custom fetch function

Custom fetch usage, e.g. on a local filesystem:

import remoteModel from 'remote-model'
import fs from 'fs/promises'

const myModel = remoteModel({
  async fetcher() {
    return fs.readFile('local-model-to-watch.json', 'utf8')
  },
  updateIntervalMs: 2 * 60 * 1000 // 2 minutes
})

myModel.fetch().then((data) => {
  console.log('[My Custom Fetch Model]', data)
})

myModel.notify((data) => {
  console.log('[My Custom Fetch Model] Updated', data)
})

HTTPS Agent

In order to access content securely over HTTPS, the https lib is used to create a https agent for network requests. It is recommended that you set up the following environment variables prior to running your script. By default, the script expects the CLIENT_CERT, CLIENT_KEY, and CLIENT_CA to exist, for example:

export CLIENT_CERT="/user/certs/path.crt"
export CLIENT_KEY="/user/certs/path.key"
export CLIENT_CA="/user/certs/ca_bundle.crt"

Changelog

2.0.0

  • Change project type to module
  • Rewrite require to use module imports
  • Rewrite tests to use module imports
  • Change process.env to import.meta.env

1.1.1

  • Dependabot patches to package dependencies
  • Please consider upgrading to ^2.0.0

1.1.0

  • Add support for custom fetch function
  • Remote model can now cache any execute kind of asynchronous fetch operating
  • Updated code base to use Node 14 LTS features

1.0.3

  • Fix promise rejection on outstanding promises

1.0.2

  • Add information about HTTPS Agent

1.0.1

  • Add repository information to package.json

1.0.0

  • Extracted first version from existing project
  • Added tests for fetch and notify