What is Runtime?

A runtime environment is a software environment in which a program or application runs. It provides the necessary resources and services for the execution of the program, including memory management, input/output operations, and access to system resources.
Example of Runtime C++
  The C++ runtime library provides the necessary functions and classes for managing memory, handling input/output operations, and providing other essential services for C++ programs.

What is Bare Runtime?

Bare Runtime is a minimal JavaScript runtime environment that provides the essential features needed to execute JavaScript code without the overhead of a full-fledged runtime like Node.js browser environments.
It is designed for scenarios where you want to run JavaScript code in a lightweight applications eg(embedded systems, IoT devices, or other resource-constrained environments).

How to Use Bare

write a standard JavaScript file and execute it using the Bare binary or environment

C++ Code, that can be used by JavaScript

#include <node_api.h>

// A simple C++ function that adds two numbers
napi_value Add(napi_env env, napi_callback_info info) {
    size_t argc = 2;
    napi_value args[2];
    napi_get_cb_info(env, info, &argc, args, NULL, NULL);

    double arg0, arg1;
    napi_get_value_double(env, args[0], &arg0);
    napi_get_value_double(env, args[1], &arg1);

    napi_value sum;
    napi_create_double(env, arg0 + arg1, &sum);

    return sum;
}

// Initialize the module and export the 'add' function
napi_value Init(napi_env env, napi_value exports) {
    napi_property_descriptor desc = {
        "add", 0, Add, 0, 0, 0, napi_default, 0
    };
    napi_define_properties(env, exports, 1, &desc);
    return exports;
}

NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
        
Build this C++ code into a shared library
(e.g., addon.node on Windows/Linux or .dylib on macOS)
Consume in Javascript

// Load the compiled C++ native addon
const addon = require('./build/Release/addon.node');

// Call the C++ function seamlessly from JavaScript!
const result = addon.add(5, 10);
console.log('Result from C++ API:', result); // Output: Result from C++ API: 15