n8n-nodes-script-runner
v1.20.0
Published
Custom n8n nodes for script execution (jsdom, cheerio) and HTTP requests (axios, fetch)
Maintainers
Readme
n8n Script Runner Node
A custom n8n node package that includes:
- Script Runner: Run custom JavaScript scripts with jsdom or cheerio for HTML parsing
- HTTP Request Runner: Execute HTTP requests with axios
- LinkedIn Fetcher: Fetch LinkedIn data via Unipile API
- HTML to PDF Converter: Convert HTML content or URLs to PDF files
Features
Script Runner
- ⚡ 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
HTML to PDF Converter
- 📄 Convert HTML strings to PDF files
- 🌐 Convert web pages (URLs) to PDF
- ⚙️ Configurable page format (A4, A3, Letter, Legal, Tabloid)
- 🎨 Support for custom orientations
- 💾 Output as binary data or base64 string
- 🚀 Lightweight - no browser required (uses PDFKit)
- 📝 Extracts headings and paragraphs from HTML
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
HTML to PDF Converter
Example 1: Convert HTML String to PDF
Configure the node with:
- HTML Source: HTML String
- HTML Content: Your HTML code
- Output Format: Binary Data
- File Name: output.pdf
Example 2: Convert Web Page to PDF
Configure the node with:
- HTML Source: URL
- URL: https://example.com
- Output Format: Binary Data
- Page Format: A4
- Landscape: false
Example 3: Custom Margins and Settings
{
"htmlSource": "string",
"htmlContent": "<html><body><h1>Invoice</h1><p>Total: $100</p></body></html>",
"outputFormat": "binary",
"fileName": "invoice.pdf",
"pageFormat": "Letter",
"margin": {
"top": "20mm",
"right": "15mm",
"bottom": "20mm",
"left": "15mm"
},
"printBackground": true,
"landscape": false
}The PDF will be available as binary data that can be saved to disk or sent via email in subsequent nodes.
Script Runner - 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();
conHTML to PDF Converter
### Example 1: Convert HTML String to PDF
Configure the node with:
- **HTML Source**: HTML String
- **HTML Content**: Your HTML code
- **Output Format**: Binary Data
- **File Name**: output.pdf
### Example 2: Convert Web Page to PDF
Configure the node with:
- **HTML Source**: URL
- **URL**: https://example.com
- **Output Format**: Binary Data
- **Page Format**: A4
- **Landscape**: false
### Example 3: Custom Margins and Settings
```json
{
"htmlSource": "string",
"htmlContent": "<html><body><h1>Invoice</h1><p>Total: $100</p></body></html>",
"outputFormat": "binary",
"fileName": "invoice.pdf",
"pageFormat": "Letter",
"margin": {
"top": "20mm",
"right": "15mm",
"bottom": "20mm",
"left": "15mm"
},
"printBackground": true,
"landscape": false
}The PDF will be available as binary data that can be saved to disk or sent via email in subsequent nodes.
Script Runner Usage Examples
Example 1: Extract Text with Cheerio'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 parameter
- `items` - All input items array
- `$item` - Current item being processed
- `itemIndex` - 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
```bash
# 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.
