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

codehelp-compiler

v1.0.2

Published

A library that allows you to run programs in 5 languages using node.js, useful for creating online IDE's and similar projects.

Downloads

6

Readme

CodeHelp Compiler

  • The library functions as an interface for the compilers on your system.
  • It offers APIs to launch child processes and run programs.
  • It comes equipped with type support.
  • It is compatible with both asynchronous programming using async/await and promises.

Supported Languages

  • C
  • C++
  • Java
  • JavaScript(Node.js env)
  • Python

Prerequisites

The following must be installed on your machine and its location must be added to your PATH.

| Language | Software | |---------|:-------:| |C | gcc | |C++ | gcc | |Java | jdk | |Python | python | |JavaScript(in node.js environment) | node.js |

The source files for programs are stored in a folder named .codehelp-compiler located in the home directory. Ensure that you have the necessary permissions for this folder.

Installation

You can install it by using npm like below.

npm install codehelp-compiler --save

oe by using yarn like below.

yarn add codehelp-compiler

Usage

It consists of 5 modules, each dedicated to a specific language.

const {c, cpp, node, python, java} = require('codehelp-compiler');

The modules each have two functions:

1. runFile

This function allows you to run a file and requires the file path as an argument. Options and a callback function can be provided as optional arguments.

2. runSource

This function enables the direct execution of source code stored in a string. The source code must be provided as an argument, with options and a callback function as optional inputs.

Examples:-

- Running a C++ source code file

let resultPromise = cpp.runFile('C:\\example.cpp', { stdin:'3\n2 '});
resultPromise
    .then(result => {
        console.log(result); //result object
    })
    .catch(err => {
        console.log(err);
    });

- Running a python source code string

const sourcecode = `print("Hello World!")`;
let resultPromise = python.runSource(sourcecode);
resultPromise
    .then(result => {
        console.log(result);
    })
    .catch(err => {
        console.log(err);
    });

- Using Callbacks

You can pass a callback by including it as:

  • an optional argument in case of runFile
    cpp.runFile('C:\\example.cpp', { stdin:'3\n2 '}, (err, result) => {
        if(err){
            console.log(err);
        }
        else{
            console.log(result);
        }
    });
  • without an option
    cpp.runFile('E:\\abcd.cpp', (err, result) => {
        if(err){
            console.log(err);
        }
        else{
            console.log(result);
        }
    });

- Providing path

// Providing custom path in java
java.runFile('C:\\Main.java',{
    compilationPath: '<path to javac>',
    executionPath: '<path to java>'
},(err,result)=>console.log(err ? err : result));
// if you have 2 versions of python installed 2.7 and 3.6, you can use 3.6 using python3
// to run python3 using codehelp-compiler you can do something like
python.runFile('/home/projects/scripts/example.py',{
    executionPath: 'python3'
},(err,result)=>console.log(err ? err : result));
// if you want to provide custom path of gcc in cpp
cpp.runFile('C:\\example.cpp',{
    compilationPath: '<path to gcc>' // something like C:\\Program Files\\gcc\\bin
},(err,result)=>console.log(err ? err : result));

Result

The Result object has the following keys:

  1. exe <string> - The path to the executable file generated after successful compilation.
  2. stdout <string> - The standard output of the program execution. If the output is empty, an empty string is returned.
  3. stderr <string> - The standard error of the program execution, compilation, or if the public class name is not found in the provided source string (in Java). If there is no error, an empty string is returned.
  4. exitCode <number> - The exit code of the program.
  5. errorType <string|undefined> - If there is an error or a non-zero exit code, this is set to one of the following values:
    1. 'pre-compile-time' - Only in the case of Java. This can occur if the public class name is invalid when using runSource for Java.
    2. 'compile-time' - If an error occurs during compilation.
    3. 'run-time' - If an error occurs during runtime.
  6. cpuUsage <number> - The CPU time, in microseconds.
  7. memoryUsage <number> - The amount of memory consumed, in bytes.
  8. signal <string|null> - The signal, if any, resulting from the code execution.

Disclaimer: The accuracy of cpuUsage and memoryUsage is not guaranteed.

Options

The following is an optional options object that can be provided to the API:

  1. stdin <string> - The input or standard input that you want to pass to the program.
  2. timeout <number> - The time limit for program execution in milliseconds. The default value is 3000 milliseconds.
  3. compileTimeout <number> - The time limit for compilation for C, C++, and Java in milliseconds. The default value is 3000 milliseconds. This will be ignored if passed for Node or Python.
  4. compilationPath <string> - The path to the compiler for C, C++, and Java (i.e., GCC and javac, respectively). If provided, the paths defined by you will be used. If not, the default paths will be used.
  5. executionPath <string> - The path to the command used to execute the program for Java, Python, and Node.js (i.e., java, python, and node, respectively). If provided, the paths defined by you will be used. If not, the default paths will be used.