Welcome folks today in this blog post we will be downloading website source code
including the html,css and javascript
files from url
for offline use
in node.js. All the full source code of the application is shown below.
Get Started
In order to get started you need to initialize a new node.js
project using the below command as shown below
npm init -y
npm i node-site-downloader
And now basically you can execute the below command to download
the website source code from the url as shown below
Usage
1 |
node-site-downloader download DOMAIN START_POINT OUTPUT_FOLDER [VERBOSE] [OUTPUT_FOLDER_SUFFIX] [INCLUDE_IMAGES] |
Here in the above command we need to replace the DOMAIN
name and also you need to provide the path for the output_folder
and also you need to provide the images
suffix to fetch
images also
1 |
node-site-downloader download -s https://jestjs.io/docs/en/getting-started -d https://jestjs.io/docs/en/ -o jest-docs -v --include-images |
As you can see it will create the directory
of the website and inside it we have the html,css
and javascript files as shown below
And now we can use the library
inside the node.js
app. For this we need to make a new index.js
file and copy paste the following code
index.js
1 2 3 4 5 6 7 8 9 10 |
const fs = require("fs"); const {exec} = require('child_process') const websiteUrl = 'https://nodejs.org/'; var directoryPath = Date.now() exec(`node-site-downloader download -s ${websiteUrl} -d ${websiteUrl} -o ${directoryPath} -v --include-images`,(err,stdout,stderr) =>{ if(err){ console.log(err) } }) |