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 🙏

© 2025 – Pkg Stats / Ryan Hefner

compilr

v1.2.16

Published

Compile and execute code

Readme

Compilr

Compilr is a powerful NPM package designed to compile code in multiple programming languages and return the output using a TD's APIs. With a simple API, it allows you to send code to be compiled and executed, and retrieve the results in a straightforward manner.

Features

  • Supports Multiple Languages: Compilr supports a wide range of programming languages.
  • Easy to Use: Simple methods to compile and execute code.
  • Handles Compilation and Execution: Manages the entire process from code submission to result retrieval.
  • Error Handling: Provides clear error messages for missing or incorrect inputs.
  • Base64 Encoding and Decoding: Handles base64 encoding for code and input data to ensure compatibility with the API.
  • Support for Large Codebases: Can handle large codebases by encoding them efficiently in base64 format.

Installation

Install using npm:

npm install compilr

Install using pnpm:

pnpm install compilr

Install using Yarn:

yarn add compilr

Usage

Require the library:

const { CompilerClient, CompilerRequestDto } = require('compilr');

Create a Compiler Client Instance

const compilerClient = new CompilerClient();

Prepare the Code for Compilation

const code = `
for i in range(1, 11):
    print(i)
`;

const requestDto = new CompilerRequestDto(code, 'python');

Compile and Execute the Code

compilerClient
  .compileAndExecute(requestDto)
  .then((response) => {
    console.log('Output:', response.stdout);
    console.log('Compilation Time:', response.time);
    console.log('Memory Usage:', response.memory);
  })
  .catch((error) => {
    console.error('Error:', error.message);
  });

API Reference

CompilerClient

Compiles and executes the given code.

  • Parameters:

    • data: An instance of CompilerRequestDto containing the code, language, and optional input.
  • Returns:

    • A Promise that resolves to an instance of CompilerResponseDto containing the output, compilation time, memory usage, and other details.

CompilerRequestDto

A DTO (Data Transfer Object) representing the request data for compilation.

  • Properties:
    • code (string): The source code to be compiled.
    • language (string): The programming language of the source code.
    • stdin (string, optional): The standard input for the program.

CompilerResponseDto

A DTO representing the response data from the compilation and execution.

  • Properties:
    • stdout (string | null): The standard output of the program.
    • time (string): The time taken for compilation.
    • memory (number): The memory used during execution.
    • stderr (string | null): The standard error output of the program.
    • token (string): The unique token for the compilation request.
    • compile_output (string | null): The output of the compilation process.
    • message (string): Any additional messages from the server.
    • status (object): The status of the compilation request, with id and description.

Error Handling

Compilr provides clear error messages for common issues such as missing required fields or unsupported languages.

Example Error Handling

try {
  await compilerClient.compileAndExecute(requestDto);
} catch (error) {
  console.error('Error:', error.message);
}

Available Programming Languages with Keywords

Compilr supports a wide range of languages, including but not limited to:

  • Assembly - assembly
  • Bash - bash
  • C - c
  • C# - csharp
  • C++ - cpp
  • Erlang - erlang
  • Go - go
  • Java - java
  • JavaScript - javascript
  • PHP - php
  • Python - python
  • Ruby - ruby
  • Rust - rust
  • TypeScript - typescript
  • Kotlin - kotlin
  • Objective-C - objectiveC
  • R - r
  • Scala - scala
  • SQLite - sqlite
  • Swift - swift
  • Perl - perl
  • Clojure - clojure

Example Code Snippet

const { CompilerClient, CompilerRequestDto } = require('compilr');

const compilerClient = new CompilerClient();

var data = {
  language: 'python',
  code: 'print("Hello")',
  input: '',
};

compilerClient
  .compileAndExecute(
    new CompilerRequestDto(data.code, data.language, data.input),
  )
  .then((result) => {
    console.log('Output:', result.stdout);
    console.log('Compilation Time:', result.time);
    console.log('Memory Usage:', result.memory);
  })
  .catch((error) => {
    console.error('Error:', error.message);
  });

Response Example

Successful Response

{
  "stdout": "Hello\n",
  "time": "0.049",
  "memory": 3264,
  "stderr": null,
  "token": "b3e5c26d-44dd-4bd0-9619-45b071464243",
  "compile_output": null,
  "message": null,
  "status": {
      "id": 3,
      "description": "Accepted"
  }
}

Compile Time Error Response

{
  stdout: '',
  time: null,
  memory: null,
  stderr: '',
  token: '5a9ceb8b-ebc3-461c-9668-a8f2191a9cd7',
  compile_output: 'main.cpp:2:9: error: #include expects "FILENAME" or <FILENAME>\n' +
    '    2 | #include\n' +
    '      |         ^\n',
  message: '',
  status: { id: 6, description: 'Compilation Error' }
}

Run Time Error Response

{
  stdout: '',
  time: '0.027',
  memory: 3268,
  stderr: '  File "script.py", line 1\n' +
    '    print("Hello)\n' +
    '                ^\n' +
    'SyntaxError: EOL while scanning string literal\n',
  token: 'e31129d5-35fb-42e6-9d7d-26a17104dd2a',
  compile_output: '',
  message: 'Exited with error status 1',
  status: { id: 11, description: 'Runtime Error (NZEC)' }
}

About Me

Karan Dattani


With Compilr, compiling and executing code has never been easier. Get started today and streamline your coding workflow!