Node.js And NPM Proxy Authentication

What is NPM?

NPM is an online repository for the publishing of open-source Node.js projects; second, it is a command-line utility for interacting with said repository that aids in package installation, version management, and dependency management. Many of Node.js libraries and applications are published on npm, and many more are added every day. These applications can be searched for on https://www.npmjs.com/. Once you have a package you want to install, it can be installed with a single command-line command.

Why Node.js?

So first, why do we recommend Node.js for web scraping? To answer that, let us talk about what exactly is Node.js and what are its advantages over other programming languages.

Node.js is an open-source, JavaScript runtime environment that can be used outside a web browser. Basically, the creators of Node.js took JavaScript which is mostly restricted to a web browser and allow it to run on your personal computer. With the help of Google chrome’s v8 engine, we are now able to run Javascript on our local machine which enables us to access files, listen to network traffic, and even listen to HTTP requests your machine gets and send back a file. Database can also be accessed directly much like anything you can do with PHP or Ruby on Rails.

Processing speed – Node.js is very fast, mainly thanks to Chrome’s v8 engine. Instead of using an interpreter, it uses an engine to compile JavaScript into machine code. Performance is further improved by handling concurrent requests using the event loop only in a single thread. Because it is modeled for non-blocking I/O, it reduces CPU usage when processing multiple requests at the same time.

Lightweight and highly scalable – It can handle growing workloads and perform well, making it affordable for most developers. Node.js makes it easy to update and maintain applications by decoupling each part as you add new architectures or even fix existing ones, without changing or customizing other parts of the project or application. On the development side, it is also possible to reuse and share code through modules like individual code blocks.

Node NPM Node.js Proxy Authentication

Open terminal/cmd as an administrator and paste the command there. Modify the command with credentials provided for your user:

npm config set proxy http://"username:password"@your.proxy.ip:9000
npm config set https-proxy http://"username:password"@your.proxy.ip:9000

This method can be used if you want to specify their proxy server address and port number, and type their username and password.

Node v8 and v14 Proxy Authentication

Node v8 proxy using HTTP tunnel:

const http = require('http')
const https = require('https')
const username = 'username'
const password = 'password'
const auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64')

http.request({
  host: '255.255.255.255', // IP address of proxy server
  port: 9000, // port of proxy server
  method: 'CONNECT',
  path: 'google.com:443', // some destination, add 443 port for https!
  headers: {
    'Proxy-Authorization': auth
  },
}).on('connect', (res, socket) => {
  if (res.statusCode === 200) { // connected to proxy server
    https.get({
      host: 'www.google.com',
      socket: socket,    // using a tunnel
      agent: false,      // cannot use a default agent
      path: '/your/url'  // specify path to get from server
    }, (res) => {
      let chunks = []
      res.on('data', chunk => chunks.push(chunk))
      res.on('end', () => {
        console.log('DONE', Buffer.concat(chunks).toString('utf8'))
      })
    })
  }
}).on('error', (err) => {
  console.error('error', err)
}).end()

 

Node v14 proxy example:


const http = require('http');
const https = require('https');
const username = 'username';
const password = 'password';
const auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');

http.request({
  host: '255.255.255.255', // IP address of proxy server
  port: 9000, // port of proxy server
  method: 'CONNECT',
  path: 'google.com:443', // some destination, add 443 port for https!
  headers: {
    'Proxy-Authorization': auth
  },
}).on('connect', (res, socket) => {
  if (res.statusCode === 200) { // connected to proxy server
    const agent = new https.Agent({ socket });
    https.get({
      host: 'www.google.com',
      path: '/',
      agent,      // cannot use a default agent
    }, (res) => {
      let chunks = []
      res.on('data', chunk => chunks.push(chunk))
      res.on('end', () => {
        console.log('DONE', Buffer.concat(chunks).toString('utf8'))
      })
    })
  }
}).on('error', (err) => {
  console.error('error', err)
}).end();

Get Full Access To All Of Our Residential Proxies.

Residential Plans
Mobile Plans

Starter

3GB
$45 /month
  • $15 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Email support

Hobby

15GB
$150 /month
  • $10 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Email support

Startup

40GB
$300 /month
  • $7.5 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Live chat support

Business

100GB
$600 /month
  • $6 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Live chat support

Company

250GB
$1250 /month
  • $5 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Account Manager

Enterprise

1TB
$4000 /month
  • $4 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Account Manager

Mobile A

2GB
$60 /month
  • $30 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Email support

Mobile S

5GB
$150 /month
  • $30 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Email support

Mobile M

12GB
$300 /month
  • $25 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Live chat support

Mobile L

30GB
$660 /month
  • $22 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Live chat support

Mobile XL

85GB
$1530 /month
  • $18 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Account Manager

Enterprise M

300GB
$4500 /month
  • $15 per GB
  • Rollover bandwidth
  • 150+ Countries
  • granular targeting
  • Account Manager

See How Clients Are Using Residential Proxies.

Influencer Marketing

Digital stores and brands are using our residential and mobile proxies to extract valuable influencers across social platforms to increase sales.

Ad Verification

Advertisers use ProxyEmpire's network to sniff out potential ad fraud. They use granular targeting to see their ads on all devices and locations.

Sneaker Proxies

Catch the latest sneaker drops and cop them quick with fast residential proxies that go undetected by all sneaker brand sites. 

SEO Monitoring

Check your SERP performance with GEO-specific targeting and spy on the competition without them knowing using your own crawler.

ProxyEmpire
Works With All Of Your Favorite Tools.

Learning Center