Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-chocolatey-server

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-chocolatey-server

Simple Chocolatey package server for Express

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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}`)
  });
})();

FAQs

Package last updated on 04 Oct 2023

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