Category Archives: NodeJs

How to Install a Module/Package/Library in NodeJs

Do you need to install a NodeJs module/package/library? First create the project directory: mkdir TestProject cd TestProjectmkdir TestProject cd TestProject Make the directory the root of your project: npm init –yesnpm init –yes Install the required NodeJs modules/packages (i.e “request”): npm install request –savenpm install request –save * With -save parameter, the installed modules will […]

NodeJs Request.Get Example with Error Handling

Here is an example of using NodeJs “request” library with error handling: var dateformat = require(‘dateformat’); var request = require(‘request’);   request.get(‘https://www.google.com/’,function(err, res, body) { if(err) console.error(‘[Request.Get] %s Error:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), err.message); console.log(‘[Request.Get] %s StatusCode:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), res.statusCode); });var dateformat = require(‘dateformat’); var request = require(‘request’); request.get(‘https://www.google.com/’,function(err, res, body) { if(err) […]

NodeJs HTTPS.Get Example with Error Handling

Here is an example of using NodeJs “https” library with error handling: var dateformat = require(‘dateformat’); var https = require(‘https’);   try { var httpsget = https.get(‘https://www.google.com/’, function(res) { console.log(‘[HTTPS.Get] %s StatusCode:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), res.statusCode); }).on("error", function(error) { console.log(‘[HTTPS.Get] %s Error:’, dateformat(new Date(), "yyyy-mm-dd h:MM:ss"), error.message); }); } catch(e) { console.log(‘[HTTPS.Get] %s Error:’, […]

Install Node.js Puppeteer on Debian 9 Stretch

Steps to install Puppeteer (Headless Chrome Node API) on Debian 9 Stretch. First you need to install Node.js 12.x: curl -sL https://deb.nodesource.com/setup_12.x | bash – apt-get install -y nodejscurl -sL https://deb.nodesource.com/setup_12.x | bash – apt-get install -y nodejs Then install Puppeteer module: npm install -g puppeteer –unsafe-perm=truenpm install -g puppeteer –unsafe-perm=true Now fix the “No […]

Install Node.js 12.x on Debian 9 Stretch

To install Node.js 12.x on Debian 9 Stretch just type: curl -sL https://deb.nodesource.com/setup_12.x | bash – apt-get install -y nodejscurl -sL https://deb.nodesource.com/setup_12.x | bash – apt-get install -y nodejs Some Node.js modules may require build-essential: apt-get install build-essentialapt-get install build-essential References: Installing Node.js via package manager NodeSource Node.js Binary Distributions

Install Node.js on Debian 8 Jessie

Download this bash script to update the PPA and apt repos: curl -sL https://deb.nodesource.com/setup_7.x -o nodesource_setup.shcurl -sL https://deb.nodesource.com/setup_7.x -o nodesource_setup.sh * Replace 7.x with the last Node.js version Grant +x permissions to the bash script: chmod +x nodesource_setup.shchmod +x nodesource_setup.sh Run the bash script: bash nodesource_setup.shbash nodesource_setup.sh Now install Node.js (it contains also npm): apt-get […]