{

Learn free nodejs tutorials


How to trigger System Bell from NodeJS code

February 24, 2022 ·  2 min read

A system Beep bell is a sound that plays when a new device is connected or disconnected in Operating System(Windows and macOS) Sometimes, If you are running batch scripts, you need to initiate System bell after completing node scripts. This tutorial shows multiple ways to trigger the System beep bell sound in Windows from the Nodejs program. Making sound is a part of an underline operating system native calls....


How to Create a directory in Nodejs with examples

February 20, 2022 ·  1 min read

This article covers multiple ways to create a directory Nodejs. One way using fs.mkdir using asynchronous callback, Another way using mkdirSync How do you create a directory if it doesn’t exist using node JS? Sometimes, We need to check if a folder exists or not. Nodejs provides an inbuilt fs module that provides multiple functions. This is an asynchronous version of the checking folder that exists or not. Syntax. fs.mkdirSync(path,[options]) path: the path of the folder to create options: recursive to true or false....


Best ways to fix outofmemory issue in nodejs Application in heap and process

February 19, 2022 ·  2 min read

This article, Discussed how to fix out of memory errors in Nodejs Javascript or nodejs apps throws the below error stack trace. Sometimes, the Running Nodejs application throws the below errors, making the application crashed FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed — process out of memory What is Out of memory issue? An application needs some memory to run javascript programs....


How to to get file metadata information in Nodejs app| fs stat example

February 19, 2022 ·  3 min read

file contains content and type. Apart from this, you will have metadata of a file It is very easy to get the file information in Operating System such as windows. How do you get file metadata information in Nodejs? Nodejs provides inbuilt module - fs and it contains stat() and statSync() method to get metadata properties of an file or a directory. It provides two methods fs....


Learn npm runtime configuration file| .npmrc file example

February 19, 2022 ·  4 min read

Did you observe nodejs project has several RC dotfiles like .npmrc, .babelrc generated in a nodejs project? In this tutorial, learn about the contents of npmrc with below things npmrc file create how to add registry and scoped multiple registries npm config set, get the list npmrc auth token configuration npmrc file location in windows How to create an npm runtime configuration npmrc sample file example parsing RC file in nodejs For example, We have different RC files in different applications...


Multiple ways to log the printstack trace in Nodejs

February 17, 2022 ·  2 min read

In Nodejs, There are multiple ways to print an error stack trace in nodejs. Stacktrace is displayed when an unexpected error by a nodejs javascript engine. It helps developers to debug and fix the issues. Stacktrace gives a method line number call stack trace in Last In First Out (LIFO). How to Print error stack trace in Nodejs? There are multiple ways we can do in javascript and nodejs using try and catch try and catch provides used to catch exceptions the code....


Nodejs Error captureStackTrace example| Javascript print stack trace as a string

February 17, 2022 ·  1 min read

In Java, We use to print the stack tracce with inbuilt method. In Nodejs, It provides captureStackTrace method in Error object to get call stack information. It creates .stack property with information to an target object. It provides user defined function to capture the stack call trace. Syntax: captureStackTrace(Object[, constructorFunciton]) Object: It is an target error object which returns string that contains line number in location code with stack trace. An constructorFunciton: Error custom object...


Difference between npm and npx| Comparision of npm and npx with exmaple

February 13, 2022 ·  2 min read

In Nodejs, We have two commands to manage and run libraries npm: Node Package Manager npx: Node package executable runner The above two come with default nodejs installation. What is npm? npm is an easy command-line tool to manage(install, uninstall) node javascript packages in Nodejs. It is not easy to run and execute the installed packages with this. What is npx? npx is the command-line tool to run the packages locally without the installation of packages....


How to use executables from a package installed locally in node_modules?

February 13, 2022 ·  2 min read

This tutorial uses how to run executable files from the node_modules folder of an application. Npm packages are installed locally or globally using the npm install command. Locally: In your application, if you run npm install package, It installs to node_modules folder and the It creates an link to node_modules.bin folder Globally: npm install package -g It installs to global node_modules folder(/usr/local/ in Unix, %AppData%/npm in windows.). Path to binary folder is /usr/local/bin folder in Unix and...


Multiple ways to read local json file in Nodejs application

February 11, 2022 ·  1 min read

In this tutorial, Learn what is about x-tag web components, How to create web component using x-tag in javascript. What are x-tag in html? X-tag is lightweight webcomponent library supported by Microsoft. It is javascript library API to create a web components similar to div,audio and video tags. life cycle methods There are different life cycle methods for a created web component created - This handler called whenever component object is created in DOM...


How to restart node server forever | Nodejs forever npm library

February 9, 2022 ·  2 min read

This tutorial shows how to keep the node server alive continuously and also how to restart the node server after an error or crash. forever npm library provides a CLI tool to keep node server continuously running. It restarts a server if the node server stopped because of an error. It provides the following ways to integrate into node application CLI tool Code Nodejs forever server alive First, install forever npm library into an application...


Multiple ways to get NodeJS version with examples

February 9, 2022 ·  2 min read

This tutorial shows multiple ways to know the installed node and npm version. How to get Node and npm versions in the command line. Open terminal, type below command node --version or node -v C:\>node --version v14.17.0 node –version gives nodejs version installation number. If you got the below error, node: command not found without a print version number, Then the probable cause is nodejs is installed correct version or node path is not correctly set in environment variables....


Best ways to get package.json version in NodeJS with examples

February 5, 2022 ·  1 min read

This tutorial shows multiple ways to get a package.json version of a nodejs application. There are multiple ways we can read package.json file in Nodejs Application. First Way, using require and import, Second-way using fs module read json file. Nodejs Get Version of package.json application using require and import if you are using the ES5 javascript version, use require keyword import json file using require keyword and create a variable, use the version variable directly using the imported variable var packageJson = require('....


Multiple ways to Call REST API from Nodejs Application| Consume REST API

February 2, 2022 ·  2 min read

Sometimes, Application requires to call Remote or external API from a nodejs Application. It covers following items How to call remote REST API from nodejs application How to get data from http get request data How to make http get and post request Get HTTP request body in nodejs Process post request in NodeJS Nodejs is server side code based on npm libraries. Consume REST API involves http requst of type GET/POST/DELETE/PATCH...


How to find Operating System username in NodeJS?

January 24, 2022 ·  1 min read

This example shows multiple ways to get the current logged username of the running Operating System. Each OS has a login profile to log into System. Programm to retrieve current logged OS username in NodeJS Nodejs os module provides current Operation System information. userInfo() function returns an object containing OS information of a user and directory. First, Import os module into code using require() function. Here is an example code...


How to generate package-lock.json in nodejs forcebly with npm

January 23, 2022 ·  1 min read

package-lock.json files are generated automatically while running npm install or npm update. It also generates any changes to the recursive node_modules folder tree. Sometimes, the developer deletes this or only wants to update this file. This post shows you many ways to generate or update the package-lock.json file in NodeJS. However, this can be disabled in the .npmrc settings file with package-lock=false. Please check the home directory ....


How to check current operating system in Nodejs?

January 22, 2022 ·  2 min read

This example shows how to get the currently running operating system using nodejs code. Sometimes, We need to run the shell or batch script based on a currently running system. If OS is windows, use batch(.bat) file. Use shell (.sh) script for Linux and macOS. Nodejs API programmatically Using command line How to get current running Operating System using Nodejs? There are multiple ways to get OS in Nodejs programmatically, One way is using process....


Different ways to kill or stop node process in Windows and Linux

January 2, 2022 ·  3 min read

When you start running an API nodeJS server, a frontend web server, and a test case, a NodeJS process is created. You may also use the command line or the Visual Studio code terminal to run all of these. Angular, React, and Vuejs are examples of front-end frameworks. Sometimes, You may need to stop a single process or all processes for debugging. Other way, You closed Visual Studio code without terminating the node process running in terminal....


Guide to Package.json file tutorial in Nodejs Applications

January 2, 2022 ·  6 min read

In this blog post, We are going to learn package.json tutorials with examples Package.json file package.json is a JSON configuration file of nodejs and javascript-based projects. It contains key and value of Nodejs based applications. The location of this file is in the root folder of the application. This will be used by the npm command for build/starting/testing your javascript-based applications. This will help other developers to track the application dependencies and versions This file can be created in many ways as follows...


How to check the file/path exists in Nodejs?

January 2, 2022 ·  2 min read

This is a simple tutorial on how to check if a file exists in a file system using nodejs code. We can use a variety of methods to see if a file exists in Nodes. Using existsSync and exists fs access and accessSync Async and await promises File checking can be done Synchronous and asynchronous. fs exists function fs provides two functions to check file path exists in a OS file system....


How to Convert Buffer to ArrayBuffer in NodeJS with example

January 2, 2022 ·  2 min read

In this post, Learn how to convert the buffer to/from ArrayBuffer in Nodejs application with example. Buffer is an object in Nodejs to represent a fixed length of bytes. ArrayBuffer also stores the fixed length of the array of binary bytes data in javascript. Data inside array buffer can not be read directly but you can use Data view Object or typed array only. Some of the typed Arrays are Int8Array, UInt8Array, Float32Array, etc....


How to Convert word document to pdf in Nodejs| Javascript example

January 1, 2022 ·  4 min read

In this post, You will learn how to convert Docx files to pdf documents in JavaScript and nodejs. Docx/doc are document file formats from Microsoft, contains images, text, tables, and styles PDF files are from Adobe company, which is a separate format for representing the content of images, texts, and styles There are a lot of online tools to do the conversion doc to pdf. Sometimes, As a programmer, you need to have a conversion of different formats in the JavaScript/NodeJS applications....


2 ways to Convert xml to JSON in Nodejs | Javascript example

January 1, 2022 ·  4 min read

This tutorial explains how to convert XML to JSON In javascript and Nodejs Applications. XML is an extensible markup language that contains properties or tags in the parent tag relation. JSON is a simple format to have a key and values pair enclosed in parenthesis{}`. Both are used to store different types of data, there is no manual conversion from one type to another in nodejs and javascript...


Best ways to read local json file in Nodejs application with example

January 1, 2022 ·  3 min read

In this tutorial, multiple ways to read local JSON files in Nodejs application using required js fs module readFile Let’s declare a local JSON file in the nodejs project emp.json { "id": 1, "name": "John", "salary": 5000 } easy way to read local json file with require to function in nodejs This is an simple and easy way to read using require function const json = require("....


Dependencies vs devDependencies vs peerDependencies in Nodejs

January 1, 2022 ·  4 min read

Nodejs Dependency types In Nodejs projects, npm is the default package manager to manage the dependencies. In every application development on any language, dependencies are required to build and start running the application. Every application has a dependency tree that contains all direct and indirect dependencies. Dependency is a module or library code that is required to execute the application. Each dependency is also called a package, that contains the name and version declared in package....


ERESOLVE unable to resolve dependency tree when npm install runs in nodejs and netlify

January 1, 2022 ·  3 min read

npm install is a command to install dependencies of an application. Sometimes, When you are running npm install, You will get dependency error npm ERR! ERESOLVE unable to resolve dependency tree. as seen below. 5:43:24 PM: Installing NPM modules using NPM version 7.11.1 5:43:33 PM: npm ERR! code ERESOLVE 5:43:33 PM: npm ERR! ERESOLVE unable to resolve dependency tree 5:43:33 PM: npm ERR! 5:43:33 PM: npm ERR! Found: compression-webpack-plugin@3....


Fix for error package.json not found in npm install running

January 1, 2022 ·  3 min read

In this blog post, learn how to fix the “package.json not found” error in the npm command. Fix package.json not found an error package.json is a JSON configuration file of a nodejs project which contains metadata of an application + dependencies etc. In NPM based applications such as nodejs, Angular, VueJS, and ReactJS applications, the package.json file location is the application root. When you are creating a new project manually or when installing project dependencies we used to get the following errors....


Fix for Invalid configuration object: Unknown property query webpack and babel

January 1, 2022 ·  2 min read

Recently, I am working on upgrading one of the node applications with the latest versions and My Application uses the webpack build tool. I upgraded nodejs webpack and all dependencies to the latest version. Got an error after upgrading to the latest version for webpack. Here is an error after running npm run start on my node application. PluginError [ValidationError]: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema....


Fix for node-sass build error in netlify build

January 1, 2022 ·  2 min read

In this tutorial, learn how to fix an error for the installation of node-sass during the netlify build. I got this error during node project deployment in netlify production 4:54:23 PM: npm WARN rm not removing /opt/build/repo/node_modules/.bin/gulp as it wasn't installed by /opt/build/repo/node_modules/gulp-cli 4:54:23 PM: > node-sass@6.0.1 install /opt/build/repo/node_modules/node-sass 4:54:23 PM: > node scripts/install.js 4:54:23 PM: Unable to save binary /opt/build/repo/node_modules/node-sass/vendor/linux-x64-57 : { Error: ENOENT: no such file or directory, mkdir '/opt/build/repo/node_modules/node-sass/vendor/linux-x64-57' 4:54:23 PM: at Object....


gitignore nodejs |how to ignore node_modules

January 1, 2022 ·  2 min read

This tutorial will show you how to add a.gitignore file to your Nodejs application and its contents. The.gitignore file contains entries for the names of files and folder paths that can ignore when committing source code to nodejs projects. In nodejs applications, which files or folders are ignored? Below are list of file or folder types dependencies log files dotenv environment variables configuration serverless folder IDE related configuration cache files typescript and javascript related files how to ignore node_module dependencies in gitignore files node_modules dependencies: The application has a lot of dependencies specified in package....


How to add Lodash in Nodejs with examples?

January 1, 2022 ·  4 min read

We’ve already covered some of the basics of the Lodash library in front-end applications. You can check other posts cover the basic usage in Client-side applications Learn Lodash basics with examples Import Lodash in Angular applications This article walks through how we can use lodash in backend applications using nodejs. The node package management tool comes standard with the Nodejs environment, and it’s a need to before you start using it....


How to check the built nodejs environments v8 engine version

January 1, 2022 ·  2 min read

The V8 engine is used internally by Nodejs, a javascript runtime environment. Every year, JavaScript introduces new features into the language. To implement these features into a nodejs project, we need to use babel plugins or a v8 engine version that supports the new javascript features. This post discusses various methods for showing the V8 version of the Nodejs Environment. The command-line utility node and npm include in Nodejs installation....


How to Convert Relative to Absolute path in Nodejs | Javascript

January 1, 2022 ·  2 min read

In this short tutorial, You will learn how to convert relative path to absolute path in Nodejs Application with example. absolute path and relative path in Nodejs A resource path that starts at the application root is known as an absolute path. i.e. always begins with the /. Relative path is a relative path to the resource, which does not begin with /. Let’s say, you have a NodeJS application with the following directory or folder structure....


How to execute shell script file from Nodejs Application

January 1, 2022 ·  4 min read

Sometimes, We want to execute the shell or bash script files from nodejs code, This tutorial talks about how to run shell script files from a javascript code and command line in nodejs application. Why do we need to run shell script file from nodejs program It is helpful to automate the server-side tasks with running a unix shell script from a javascript program Batch job execution to send email or copy or delete or sync files between file systems....


How to get return url in nodejs application|http referrer header example

January 1, 2022 ·  2 min read

Sometimes, We need to get the Referer HTTP header in the Node application. This post explains how to find the referer URL in the Nodejs application. This tutorial describes all the steps to retrieve referer in javascript [Referer](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36) is an HTTP optional header in a request that contains a domain or a page URL making the request. some times Referer is also called referrer as old browsers still reference this....


How to measure time taken by function to execute Javascript

January 1, 2022 ·  3 min read

In this blog post, JavaScript offers ways to calculate measure (elapsed) time taken by a function execution in JavaScript and NodeJS. Sometimes, we need to know function execution time while profiling a JavaScript application to improve performance. It helps the developer to pinpoint the problem method for the time taken. Time elapse taken in JavaScript. Measure time in NodeJS. How to measure time taken for function execution using console object Console object is an inbuilt JavaScript object useful for getting debugging information during development....


How to read keystrokes from standard input in nodejs example

January 1, 2022 ·  2 min read

Sometimes, Nodejs code allows listening to the keyboard events to do some processing related to hardware or script automation. Keyboard has different events. keypress keydown Nodejs has an inbuilt object called a process that has a stdin function to read the stream from the keyboard network. Nodejs read keystrokes data and display it to the user In this example, Create an stdin object using one the below approaches...


How to update dependency to latest in nodejs|npm outdated

January 1, 2022 ·  4 min read

In My previous nodejs application, I need to convert all dependencies to the latest. This blog talks about how to upgrade all your packages to the latest version This post solves developers questions while nodejs update the latest packages How do update each dependency in package.json how to update all packages manually or automatically how to update global packages to the latest versions update dependencies and devdependencies Nodejs project all dependencies maintained in package....


How to validate URL and domain in Nodejs with examples

January 1, 2022 ·  2 min read

It is a short tutorial on how to validate the below things in Nodejs Application. validate URI domain name validation validation on URI is to check valid URL or not and Domain validation is to check URL contains HTTP or HTTPS and extension is present How to check Domain URL validation with HTTP or HTTPS in nodejs Sometimes, We want to check abc.com is a valid URL or not...


Learn how to create an web server in Nodejs application with example writing custom code with http module and using http-server npm library

January 1, 2022 ·  2 min read

Understanding Nodejs Nodejs is an open-source framework for building Server-side applications based on javascript. It is a javascript runtime based on the Chrome V8 Javascript engine. You can write your web server using this environment. Nodejs is growing popular day by day because of its features, simplicity, and architecture. Nodejs can run on any operating system like Windows, macOS, and Linux/Unix/Ubuntu. It is platform Independent. Nodejs Advantages or pros Provides Non-Blocking and Event-Drive programming features to handle the concurrent request It is based on javascript Scalable and network applications can build with simple code Simple to learn It is a single-threaded model Performance is good as it uses javascript on the server-side Disadvantages or cons Learning Curve Not suitable for Multithreaded Model Not enough tools Basic Web server Example web server is a server in which clients send the request to the server, in turn, the server returns a response....


Netlify update node and npm version for production

January 1, 2022 ·  2 min read

This short tutorials explain about How to set node and npm versions in netlify? This post answers the below questions set latest nodejs version in netlify upgrade node and npm versions production build Change outdated nodejs version There are multiple ways we can upgrade the node version. First way, use .nvmrc file Adding .nvmrc file. Go to your project root folder, Create a file .nvmrc...


Nodejs Copy Directory using npm script | copyfiles npm example

January 1, 2022 ·  3 min read

This tutorial covers how to copy files with script tags command in package.json copy files from one folder to another folder npm script to copy directory including nested directory There are many npm packages to copy files, In this example, I am going to use copyFiles npm package. Advantages with npm copy As you are not worried about remembering the copy command in OS environment, This will take care of running on Windows, Mac, Unix flavors...


Nodejs v8 getHeapSpaceStatistics method | Heap space statistics in node

January 1, 2022 ·  3 min read

In this tutorial, You learn v8.getHeapSpaceStatistics() method in v8 module of nodejs with examples getHeapSpaceStatistics method returns statistics about heap sizes based on spaces. v8 is an opensource javascript engine from google chrome and used by nodejs and MongoDB What is a space in v8? Space is a chunk of memory allocated by the v8 engine. V8 has the following different spaces for storing and garbage cleaning objects in heap memory....


NodeJS v8 getheapstatistics method| How to find heap size?

January 1, 2022 ·  2 min read

In this tutorial, You learn the getHeapStatistics method in the v8 module of nodejs with examples This includes how to find below things from javascript code How to get the value of max_old_space_size from the code? get max heap size of a nodejs application Retrieve heap memory for string objects total_available_size max-old-space-size V8 is an engine is used internally by Nodejs environment. You can check v8 version and 32 bit or 64 bit for Nodejs...


Nodejs, How to Convert xml to CSV| Javascript

January 1, 2022 ·  3 min read

You can check more about xml and json types Nodejs Application In Javascript, there is no direct solution to convert XML to JSON, We have npm library @wmfs/xml2csv . First, Let’s create a nodejs application using npm init command npm init npm init -Y This command creates a nodejs application with all default values Next, Install @wmfs/xml2csv dependency to an application using below command npm install xml2csv --save This adds dependency in package....


npm-check-updates update packages in package.json and bower.json | ncu command in nodejs

January 1, 2022 ·  4 min read

In this blog post, We are going to learn npm-check-updates npm package to update dependencies in package.json and bower.json. npm package update npm, check updates package is used to check all dependencies in package.json of a node js project and update dependencies to latest versions. This package works by updating the following configuration files package.json bower.json This library solves all below problems of a NodeJS application...


Sass compile and watch changes Nodejs|node-sass tutorial

January 1, 2022 ·  4 min read

Nodejs SASS npm library Sass is a pre-processor language that is converted to CSS, It provides a lot of features variables, inherence, and mixins. SASS offers two different syntaxes and does not cover detailed syntaxes in this post. SCSS SASS Sass is SASSY CSS with indent syntax, which means no braces, semicolons, and only indentation. scss syntax is similar to CSS with braces and semicolons....


Scaffolding your Nodejs Express Application| Express Generator

January 1, 2022 ·  4 min read

ExpressJS is a Framework for building backend applications using Nodejs. a yeoman is a popular tool for scaffolding an application in modern javascript applications. These tools generate standard application prototypes with required files to start up and run, generate folder structure, build files and dependencies. Expressjs has a scaffolding tool. There are two ways to generate an express application using npm commands. using express-generator tool from expressJs framework Expressjs generator for Yeoman express-generator express-generator is a command-line tool that helps in quickly creating an application....


Top nodejs node and npm command line tools tutorials

January 1, 2022 ·  3 min read

Basics of Nodejs Server Nodejs is a server platform for deploying web applications using javascript. Nodejs server is very famous in the current industry for asynchronous request processing. We can use nodejs for streaming-based applications. NodeJS is a free and open-source application to develop server-side applications. Nodejs is popular because of its event-driven and modularity-based architecture. Nodejs installation comes with node and node packaging manager (NPM) tools....


Subscribe
You'll get a notification every time a post gets published here.