![web scraping in nodejs web scraping in nodejs](https://res.cloudinary.com/practicaldev/image/fetch/s--7bsbQCzt--/c_imagga_scale,f_auto,fl_progressive,h_500,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/xovwc1mm2gxukjxajw2e.png)
After that, you'll see a list of perhaps 25 or 26 alternative post titles-it will be rather extensive. Open a terminal and launch node crawler.js at this point. The text will then be returned when you call text () on each element.
![web scraping in nodejs web scraping in nodejs](https://webdesignledger.com/wp-content/uploads/2015/01/03-le-royal-hotel-lyon-website.jpg)
![web scraping in nodejs web scraping in nodejs](https://res.cloudinary.com/practicaldev/image/fetch/s--5bA7NqMP--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/p2jevhcsumud7gqq8uhy.jpg)
You must use Cheerio to get the DOM element in order to extract the text from each title (el refers to the current element). You must loop through each post since you just need the title of each one separately. The $('div > p.title > a') is undoubtedly familiar to you if you've used jQuery. You may get a selection that can target every postcard using the aid of the browser. After that, Cheerio is fed with the HTML data using the cheerio.load() method. The Axios HTTP client library is used to perform a straightforward HTTP GET request in order to first acquire the website's HTML. The asynchronous method getPostTitles() will browse the archived r/programming forum on Reddit. Placing a simple web server as shown below: Therefore, NodeJS is a runtime environment that enables the server-side execution of JavaScript-written applications.Ĭontrary to how other languages, including C and C++, handle concurrency, NodeJS uses a single main thread and makes use of it to carry out activities in a non-nlocking way with the use of the Event Loop. Ryan Dahl, a talented developer, used Google Chrome's v8 JavaScript Engine and integrated it with a C++ application called Node to make this happen. The main goal of NodeJS was to enable server-side Javascript execution in addition to client-side execution. In contrast, servers have the ability to interface directly with the computer and its resources, enabling them to read files or keep data in databases. This indicates that JavaScript is not a type of programming language that can directly communicate with or control a computer or its resources. Your browser offers a Runtime Environment that JavaScript needs in order to communicate with it (document, window, etc.). The JavaScript Engine of the browser runs JavaScript when a webpage is loaded and transforms it into computer-readable code. It is a straightforward and contemporary language. JavaScript was first developed to offer dynamic functionality to webpages inside the browser.