
How to Build a Web Scraping API with Express.js (Sell Your Scrapers)
Turn your scrapers into a paid API. Here is how. The Architecture Client → Your Express API → Scraper → JSON Response Express.js API const express = require ( " express " ); const app = express (); app . get ( " /api/scrape " , async ( req , res ) => { const { url , selector } = req . query ; if ( ! url ) return res . status ( 400 ). json ({ error : " URL required " }); try { const cheerio = require ( " cheerio " ); const response = await fetch ( url , { headers : { " User-Agent " : " ScraperAPI/1.0 " } }); const $ = cheerio . load ( await response . text ()); const data = $ ( selector || " h1, h2, p " ). map (( i , el ) => ({ tag : el . tagName , text : $ ( el ). text (). trim () })). get (); res . json ({ url , items : data . length , data }); } catch ( err ) { res . status ( 500 ). json ({ error : err . message }); } }); app . listen ( 3000 ); Monetize It RapidAPI — list your API, get paid per call Direct sales — API key + Stripe subscription Freelance — custom endpoints per client
Continue reading on Dev.to JavaScript
Opens in a new tab



