n8n-nodes-script-runner
v1.4.0
Published
Custom n8n nodes for script execution (jsdom, cheerio) and HTTP requests (axios, fetch)
Downloads
549
Maintainers
Readme
n8n Script Runner Node
A custom n8n node that allows you to run custom JavaScript scripts with jsdom or cheerio for HTML parsing and manipulation.
Features
- ⚡ Fast HTML parsing with Cheerio (jQuery-like syntax)
- 🌐 Full DOM implementation with jsdom
- 🔧 Run custom JavaScript code within n8n workflows
- 📝 Access to input items and HTML content
- 🔄 Process multiple items in batch
Installation
Community Node Installation (Recommended)
- Go to Settings > Community Nodes in your n8n instance
- Select Install
- Enter
n8n-nodes-script-runner - Agree to the risks and install
Manual Installation
- Navigate to your n8n installation folder
- Go to custom nodes folder:
cd ~/.n8n/custom - Clone or copy this package
- Install dependencies:
npm install - Build:
npm run build - Restart n8n
Usage Examples
Example 1: Extract Text with Cheerio
// Load HTML with cheerio
const $ = cheerio.load(html);
// Extract all headings
const headings = [];
$('h1, h2, h3').each((i, elem) => {
headings.push($(elem).text());
});
return { headings };Example 2: DOM Manipulation with jsdom
// Create DOM instance
const dom = new JSDOM(html);
const document = dom.window.document;
// Query and manipulate DOM
const title = document.querySelector('title')?.textContent;
const links = Array.from(document.querySelectorAll('a')).map(a => ({
text: a.textContent,
href: a.href
}));
return { title, links };Example 3: Scrape Table Data
const $ = cheerio.load(html);
const rows = [];
$('table tr').each((i, row) => {
const cells = [];
$(row).find('td').each((j, cell) => {
cells.push($(cell).text().trim());
});
if (cells.length > 0) {
rows.push(cells);
}
});
return { tableData: rows };Example 4: Process Input Items
// Access current item
const url = $item.json.url;
// Load HTML from item
const $ = cheerio.load($item.json.html || html);
// Extract data
const title = $('h1').first().text();
const description = $('meta[name="description"]').attr('content');
return {
url,
title,
description,
processedAt: new Date().toISOString()
};Available Variables
cheerio- Cheerio library (when selected)JSDOM- jsdom constructor (when selected)html- HTML input from the node parameteritems- All input items array$item- Current item being processeditemIndex- Index of current item
Parameters
Library
Choose which library to use:
- Cheerio: Fast, lightweight HTML parser (recommended for most use cases)
- jsdom: Full DOM implementation (when you need browser-like APIs)
- Both: Access to both libraries
HTML Input
The HTML content to parse. Can be:
- Static HTML entered directly
- Accessed from input items via
$item.json.html - Left empty if processing from items
Custom Script
Your JavaScript code. Must return a value (object or primitive).
Return Full Items
- false (default): Returns only script output
- true: Merges script output with input items
Development
# Install dependencies
npm install
# Build the node
npm run build
# Development mode (watch)
npm run dev
# Format code
npm run format
# Lint
npm run lintLicense
MIT
Support
For issues and feature requests, please create an issue in the repository.
