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

express-chocolatey-server

v1.0.3

Published

Simple Chocolatey package server for Express

Downloads

25

Readme

Express Chocolatey Server

A simple Chocolatey package server for Express.

Designed to host packages for https://github.com/shaka-project/shaka-lab

If you need to serve Chocolatey packages, and the other options look too complicated, this is the server for you.

It doesn't require Windows, it doesn't require .NET, it can be deployed anywhere you can use Express, and it can be integrated into other Express-based servers. It is not a full nuget v2 API implementation, nor a full odata implementation. Rather, it implements the bare minimum to interact with the Chocolatey client.

You can use the standalone server CLI to serve the packages themselves as well as their metadata. Or, if you want to host the package files separately, you can use the module as a library and provide the package metadata.

Standalone server

If you want to host the actual package files in the same server, this is the easiest way to use express-chocolatey-server. You can use our standalone server CLI, and provide paths to all the packages you want to serve.

PORT=8000 npx express-chocolatey-server *.nupkg

Simple App Engine deployment

Start by placing your nupkg files, package.json (see below), and app.yaml (also below) in a folder.

package.json:

{
  "dependencies": {
    "express-chocolatey-server": "^1.0.0"
  },
  "scripts": {
    "start": "express-chocolatey-server *.nupkg"
  },
  "engines": {
    "node": "16.x.x"
  }
}

app.yaml:

runtime: nodejs16
handlers:
  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

Then deploy to App Engine with:

gcloud app deploy app.yaml --project=MY_PROJECT_ID_GOES_HERE

Configuring clients

The client needs to add your server as a new "source". Each source has a name. If you want your source to be named "my-awesome-packages" and your server is running at "http://10.0.0.2:8000/", you would configure your choco clients with:

choco source add -n=my-awesome-packages -s=http://10.0.0.2:8000/

Hosting packages separately

The library provides two methods:

function readPackageMetadata(path): Reads a single nupkg file and returns metadata extracted from it.

async function configureRoutes(app, prefix, packageMetadataList): Sets up Express routes for a Chocolatey server under the given prefix, and serves metadata for the packages listed.

If you want to host the packages separately from the Express server, you will want to pre-computing the package metadata, rather than maintaining it by hand.

// This is an example script for pre-computing package metadata and hosting
// packages on another server.

const chocolateyServer = require('express-chocolatey-server');

(async () => {
  // Load metadata about chocolatey packages given on the command-line.
  const packagePaths = process.argv.slice(2);
  const packageMetadataList = await Promise.all(packagePaths.map((path) => {
    return chocolateyServer.readPackageMetadata(path);
  }));

  // YOU NEED TO CUSTOMIZE THIS PART.
  // In each package entry, add a `url` field with the download URL.

  // Save this JSON to a file to be loaded in the server later.
  console.log(JSON.stringify(packageMetadataList));
});
// This is an example server using pre-computed metadata, with packages hosted
// on another server.

const express = require('express');
const chocolateyServer = require('express-chocolatey-server');

const app = express();
const port = process.env['PORT'] || 8000;

(async () => {
  // Load pre-computed package metadata in JSON.
  // These entries MUST have a `url` field.
  const packageMetadataList = require('package-metadata.json');

  // Configure chocolatey server routes at the root ('/').
  // You could also use any other route prefix you like.
  await chocolateyServer.configureRoutes(app, '/', packageMetadataList);

  // Start the server.
  app.listen(port, () => {
    console.log(`Listening on port ${port}`)
  });
})();