
Build a Competitor Price Monitor in 50 Lines of Node.js
Track competitor prices automatically with zero dependencies. The Script const https = require ( ' https ' ); const fs = require ( ' fs ' ); const competitors = [ { name : ' Store A ' , url : ' https://example.com/product-a ' }, { name : ' Store B ' , url : ' https://example.com/product-b ' } ]; async function getPrice ( url ) { return new Promise (( resolve ) => { https . get ( url , { headers : { ' User-Agent ' : ' PriceBot/1.0 ' } }, ( res ) => { let html = '' ; res . on ( ' data ' , ( d ) => html += d ); res . on ( ' end ' , () => { const match = html . match ( / \$([\d ,. ] + ) / ); resolve ( match ? parseFloat ( match [ 1 ]. replace ( ' , ' , '' )) : null ); }); }). on ( ' error ' , () => resolve ( null )); }); } async function monitor () { const file = ' prices.json ' ; const history = fs . existsSync ( file ) ? JSON . parse ( fs . readFileSync ( file )) : []; for ( const c of competitors ) { const price = await getPrice ( c . url ); const prev = history . filter ( h => h . name
Continue reading on Dev.to Webdev
Opens in a new tab



