Go Back

Download Website Source Code with Nodejs

August 9,2021

In this tutorial, we will be building a simple node.js app that will download website source code files including HTML, CSS, js, and images of the website from URL in node.js. For this, we will be using node-site-downloader which is based entirely on node-webiste-scraper, an awesome website scraper library. With this npm package, we can Download a website locally without any configuration right from your terminal. So let's get started.

Requirments

Nodejs version >= 8

Installation

npm install -g node-site-downloader

Usage

node-site-downloader download DOMAIN START_POINT OUTPUT_FOLDER
 [VERBOSE] [OUTPUT_FOLDER_SUFFIX] [INCLUDE_IMAGES]

Make sure you add the prefix https:// at the starting of the domain if you don’t write this you will get an error

Now open up a terminal and copy-paste the below command and see the magic.

node-site-downloader download -s https://google.com -d 
https://google.com -v --include-images -o sitefiles

You can see that inside the command we have some options like:

download It is a flag that you are passing to the CLI tool that you wanna download the website. It is mandatory

--include-images It is the option telling that you need to download the images of the website as well.

-d It stands for the domain option that you are passing.

-o is the output folder path.

Your files are downloaded to the folder sitefiles.

Happy Coding ...