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

@maxmouchet/julia-node-extension-demo

v1.0.4

Published

Demonstration of interfacing Julia and Node.js code.

Downloads

7

Readme

Integrate Julia and Javascript with Node.js extensions

CI Publish npm JuliaCon 2020

This repository shows how to build a Node.js native extension that calls Julia code from a precompiled system image. For an introduction in video, see the JuliaCon 2020 talk.

OverviewRequirementsRunning the extensionBuilding the extensionResources

Overview

In this repository we consider the following use case:

  • You have an algorithm written in Julia, and you want to use this algorithm in a Node.js environment.
  • You can't or you don't want to install Julia on your servers.
  • You want to avoid Julia compilation costs and you want to share data efficiently between the Julia and Node.js runtimes.

To achieve this goal, we propose a two-step approach:

  1. Build a Julia system image which includes your precompiled code.
  2. Build a Node.js native extension in C/C++ which glues together the Julia and Node.js runtimes.

The main drawbacks of this approach are:

  • It requires to write C/C++ glue code.
  • Changes to the Julia code requires re-building the system image, and (potentially) adapting the C/C++ code.

We use the following tools:

Repository structure

├── binding.gyp        # Build system configuration
├── example            # Example Express API
│   ├── app.js           # Server
│   └── test.js          # Client
├── index.js           # Extension loader
├── julia              # Julia system image
│   ├── build.jl         # System image build script
│   └── Clustering.jl    # Target package
├── node               # Node.js extension
│   ├── binding.cc       # Extension code
│   ├── extra.h          # Helpers for the Julia C API
│   └── init.h           # Helpers for Julia initialization
└── test.js            # Extension test

Requirements

  • Node.js v10.16+ (N-API v4)
  • Julia v1.4 (only for building the extension)
  • x86-64 Linux or macOS; Windows is not (yet) supported due to build issues (PR are welcome!)

Running the extension

Installation

# Requires Node v10.16+ (N-API >= 4).
# Windows is not supported (yet).

# Pre-built binaries are avaiable for Linux and macOS (x86-64).
# If you are on a different architecture, node-pre-gyp will trigger a build.
npm install @maxmouchet/julia-node-extension-demo

Example

const clustering = require('@maxmouchet/julia-node-extension-demo')
// X: dxn matrix (n d-dimensional data points) in column-major order
// k: number of clusters
clustering.kmeans(X: Float64Array, d: Number, k: Number)

See test.js and example/ for more complete examples.

Building the extension

npm install node-pre-gyp

# Run build.jl and compile binding.cc
# => dist/linux-x64-napi-v4/binding.node
./node_modules/node-pre-gyp/bin/node-pre-gyp build

# Package everything together
# => build/stage/julia-node-extension-demo/vx.y.z/Release/linux-x64-napi-v4.tar.gz
./node_modules/node-pre-gyp/bin/node-pre-gyp package

# Upload the package to Amazon S3
./node_modules/node-pre-gyp/bin/node-pre-gyp publish

Resources

Project Status

The package is tested against Julia 1.4 and Node.js v10/v14, on Ubuntu and macOS.