VOOZH about

URL: https://apify.com/martin.forejt/nodejs-runner

โ‡ฑ Nodejs Runner ยท Apify


Pricing

Pay per usage

Go to Apify Store

This Actor allows you to quickly run arbitrary JavaScript code in a real Node.js environment, making it ideal for testing, debugging, or executing small scripts without setting up a local Node.js instance. The actor spawns a separate Node.js process to run the provided code and captures the logs.

Pricing

Pay per usage

Rating

0.0

(0)

Developer

๐Ÿ‘ Martin Forejt

Martin Forejt

Maintained by Community

Actor stats

7

Bookmarked

177

Total users

6

Monthly active users

5 hours ago

Last modified

Categories

Share

Node.js Code Runner

This Apify actor allows you to quickly run arbitrary JavaScript code in a real Node.js environment, making it ideal for testing, debugging, or executing small scripts without setting up a local Node.js instance. The actor spawns a separate Node.js process to run the provided code, captures the logs (stdout and stderr), and saves them to Apify's Key-Value Store for later retrieval.

Use Case

  • Quick Testing: Instantly run JavaScript snippets in a Node.js environment.
  • Dynamic Execution: Dynamically execute and debug code from your workflows.
  • Environment Replication: Run code in an isolated environment that matches Node.js runtime configurations.

How It Works

  1. The actor receives the JavaScript code to run via its input.
  2. It spawns a child Node.js process to execute the code.
  3. Captures all logs (stdout and stderr) during execution.
  4. Saves the logs to the Apify Key-Value Store for easy access.

Input

The input should be a JSON object with the following structure:

{
"code":"<your JavaScript code here>"
}

Input Fields

  • code (string, required): The JavaScript code to execute.

Example Input

{
"code":"console.log('Hello, world!');"
}

Output

The output logs from the executed code are saved in the Key-Value Store under the key LOGS. The logs include both stdout and stderr streams, as well as the exit code of the process.

Example Logs

[
"STDOUT: Hello, world!\n",
"Child process exited with code 0"
]

Example Usage

Running the Actor

  1. Deploy the actor to the Apify platform.
  2. Provide the JavaScript code as input.
  3. Run the actor.

Sample Input

{
"code":"console.log('The current date is:', new Date().toISOString());"
}

Sample Output Logs

[
"STDOUT: The current date is: 2024-12-12T10:00:00.000Z\n",
"Child process exited with code 0"
]

Development Notes

Key Features

  • Logs Collection: Automatically collects and stores all logs for easy retrieval.
  • Error Handling: Captures errors during execution and stores them for debugging.
  • Environment Replication: Runs in a real Node.js process, ensuring consistent behavior with a local environment.

How to Retrieve Logs

After the actor runs, you can fetch the logs using the Apify SDK or API:

In Apify Console:

In the actor run details, navigate to the Key-Value Store section and find the LOGS key.

Using SDK:

const logs =await Actor.getValue('LOGS');
console.log('Retrieved Logs:', logs);

Using API:

$curl-X GET "https://api.apify.com/v2/key-value-stores/{storeId}/records/LOGS"

You might also like

Playwright Scraper

apify/playwright-scraper

Crawls websites with the headless Chromium, Chrome, or Firefox browser and Playwright library using a provided server-side Node.js code. Supports both recursive crawling and a list of URLs. Supports login to a website.

Quick Start for Actor Creation

apify/quick-start

Contains a basic boilerplate of an Apify actor with Node.js source code and a custom Dockerfile. The purpose of this actor is to help you get started quickly to create your own actors.

Vanilla JS Scraper

mstephen190/vanilla-js-scraper

Scrape the web using familiar JavaScript methods! Crawls websites using raw HTTP requests, parses the HTML with the JSDOM package, and extracts data from the pages using Node.js code. Supports both recursive crawling and lists of URLs. This actor is a non jQuery alternative to CheerioScraper.

๐Ÿ‘ User avatar

Matthias Stephens

523

Cheerio Scraper

apify/cheerio-scraper

Crawls websites using raw HTTP requests, parses the HTML with the Cheerio library, and extracts data from the pages using a Node.js code. Supports both recursive crawling and lists of URLs. This actor is a high-performance alternative to apify/web-scraper for websites that do not require JavaScript.

Camoufox Scraper

apify/camoufox-scraper

Crawls websites with stealthy Camoufox browser and Playwright library using a provided server-side Node.js code. Supports both recursive crawling and a list of URLs. Supports login to a website.

Puppeteer Scraper

apify/puppeteer-scraper

Crawls websites with the headless Chrome and Puppeteer library using a provided server-side Node.js code. This crawler is an alternative to apify/web-scraper that gives you finer control over the process. Supports both recursive crawling and list of URLs. Supports login to website.

bcv-tasa-oficial

grupoaceivzla/bcv-tasa-oficial

Crawls websites with the headless Chrome and Puppeteer library using a provided server-side Node.js code. This crawler is an alternative to apify/web-scraper that gives you finer control over the process. Supports both recursive crawling and list of URLs. Supports login to website.

Facebook Profile Phone Number Scraper

simpleapi/facebook-profile-phone-number-scraper

Facebook Profile Phone Number Scraper collects phone contact data to support audience research and outreach. Analyze niches, regions, or demographics while identifying direct contact points efficiently.

Facebook Profile Phone Number Scraper

api-empire/facebook-profile-phone-number-scraper

Automate phone number extraction from Facebook profiles with Facebook Profile Phone Number Scraper. The actor scans profiles and external links to pull available contact numbers into structured datasets for CRM enrichment.

Related articles

Web scraping with client-side Vanilla JavaScript
Read more
What is data extraction?
Read more
How to monitor local competitors on delivery platforms
Read more