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

piston-client

v1.0.2

Published

Client wrapper for the Piston API.

Downloads

163

Readme

Piston Node Client

A Node.js client wrapper for the Piston API.

Piston is a high performance general purpose code execution engine. It excels at running untrusted and possibly malicious code without fear from any harmful effects.

Installation

npm install piston-client

Usage Example

import piston from "piston-client";

(async () => {

    const client = piston({ server: "https://emkc.org" });
    
    const runtimes = await client.runtimes();
    // [{ language: 'python', version: '3.9.4', aliases: ['py'] }, ...]

    const result = await client.execute('python', 'print("Hello World!")');
    // { language: 'python', version: '3.9.4', run: {
    //     stdout: 'Hello World!\n',
    //     stderr: '',
    //     code: 0,
    //     signal: null,
    //     output: 'Hello World!\n'
    // }}

})();

Documentation

piston(options)

import piston from "piston-client";
const client = piston({});

Creates a new client. Accepts an options object as its first argument.

Options
  • server - The domain name of the Piston server to be used. Defaults to https://emkc.org.

client.runtimes()

import piston from "piston-client";
(async () => {
    const client = piston();
    const runtimes = await client.runtimes();
})();

Returns an array of available runtimes. See Piston documentation for the runtimes endpoint.

client.execute(language, code, [config])

Execute arbitrary code for a given language. Additional, optional config can be passed in the third parameter.

import piston from "piston-client";
(async () => {
    const client = piston();
    const result = await client.execute('javascript', 'console.log("Hello world!")', { language: '3.9.4 '});
})();
Options
  • language - Expects a string of the language.
  • code - Expects a string of the code to execute.
  • config - Expects an object with additional config. See Piston documentation for the available config options.

client.execute(config)

To execute Piston with more fine-tuned control, pass in a config object as the first and only parameter.

import piston from "piston-client";
(async () => {
    const client = piston();
    const result = await client.execute({
        "language": "js",
        "version": "15.10.0",
        "files": [{
            "name": "my_cool_code.js",
            "content": "console.log(process.argv)"
        }],
        "stdin": "",
        "args": ["1", "2", "3"],
        "compileTimeout": 10000,
        "runTimeout": 3000,
        "compileMemoryLimit": -1,
        "runMemoryLimit": -1
    });
})();
Options

See Piston documentation for the available options. The only difference is that the option are in camelCase as opposed to snake_case.

Error handling

Any error will return an object with the following signature:

{ success: false, error: Error }

No errors are thrown so wrapping in try / catch is unnecessary.

License

MIT © DC