In this article, we will see how we can insert data into a table using NodeJS. Read the complete article to understand how we can save data into the database table.Before proceeding, please check the following steps are already executed −mkdir mysql-testcd mysql-testnpm init -ynpm install mysqlThe above steps are for installing the Node - mysql dependecy in the project folder.Insert a Record into the Students TableFor adding the new records into the MySQL table, firstly create an app.js fileNow copy-paste the below snippet in the fileRun the code using the following command>> node app.jsExample// Checking the MySQL dependency in ... Read More
JIMP, also known as JavaScript Image Manipulation Program, is an image processing library for Node written in JavaScript with no other dependency. It allows the user to easily manipulate the and transform the images into any required shape, format, dimnesion or style. It can also be used for optimizing images to minimize the file size, ensuring high visualquality or reducing the bandwidth.Using JIMP, you can resize and crop images, convert them to the format as needed and also apply different filters and affects. Following are image formats that are supported by NodeJS JIMP −@jimp/jpeg@jimp/png@jimp/bmp@jimp/tiff@jimp/gifInstallationSetup Environment -npm init -yInstalling Dependecy -npm ... Read More
Introduction to Async ensureSymlink()This method will ensure whether the symlink exists or not. It will create the directory structure if it does not exist.SyntaxcreateSymlink(srcPath, destPah[, type] [, callback])ParameterssrcPath – The source path of the file.destPath – Destination path of the file.type – This parameter is only available on Windows and ignored on other platforms.The possible values for this parameter is dir, file or junction.callback – This function will give a callback if any error occurs.ExampleCheck that fs-extra is installed before proceeding; if not, install fs-exra.You can use the following command to check whether fs-extra is installed or not.npm ls fs-extraCreate ... Read More
This method is used to ensure that a file exists at the given location by using a sync process. The response will only be given after the processing is completed. If the files that is ensured to be created is not present or the respective directories are not present, these directories and files are created. If the file already exists, it is not modified or no change is made.SyntaxensureFileSync(file)Parametersfile – This is a string paramter which will hold the location of the file that needs to be ensured.ExampleCheck that fs-extra is installed before proceeding; if not, install fs-exra.You can use ... Read More
Introduction to Async ensureFile()This method is used to ensure that a file exists at the given location. If the files that is ensured to be created is not present or the respective directories are not present, these directories and files are created. If the file already exists, it is not modified or no change is made.SyntaxensureFile(file, [, callback])Parametersfile – String parameter which will contain name of the file and its location that needs to be ensured.callback – This function will give a callback if any error occurs.Example 1Check that fs-extra is installed before proceeding; if not, install fs-exra.You can use ... Read More
This method is used to empty a directory whether it is empty or not with a sync process. If the directory is not empty, it will remove all its contents and empty it. A new empty directory is created if the directory does not exist.SyntaxemptyDirSync(dir)Parametersdir – This is a string paramter which will hold the location of the directory structure.Example 1Check that fs-extra is installed before proceeding; if not, install fs-exra.You can use the following command to check whether fs-extra is installed or not.npm ls fs-extraCreate a syncEmptyDir.js and copy-paste the following code snippet into that file.Now, run the following ... Read More
Introduction to Async emptyDir()This method is used to empty a directory whether it is empty or not. If the directory is not empty it will remove all its contents and empty it. A new empty directory is created if the directory does not exist.SyntaxemptyDir(dir, [, callbacks])Parametersdir – This is a string paramter which will hold the location of the directory structure.callback – This function will give a callback if any error occurs.Example 1Check that fs-extra is installed before proceeding; if not, install fs-exra.You can use the following command to check whether fs-extra is installed or not.npm ls fs-extraCreate a asyncEmptyDir.js ... Read More
You can delete an existing table from MySql Database using the "DROP TABLE" statement in Node. Sometimes, we need to delete the whole table, though in corporates it is always advised to archive the tables which are not in used instead of deleting them.While deleting a table, we have two scenarios −Deleting a table if it exists, else throw an errorDeleting the table whether it exists or not.We will discuss both the scenarios here.Before proceeding, please check the following steps are already executed −mkdir mysql-testcd mysql-testnpm init -ynpm install mysqlThe above steps are for installing the Node - mysql dependecy ... Read More
NodeJS is a JavaScript runtime environment that was built on top of Chrome's V8 engine. The traditional use of JavaScript is to be executed in browsers, but with Node.JS we can execute JavaScript other than browsers like servers, hardware devices, etc.process.cwd()The process object lies under the global object known as 'global'. This method provides information about the current process of Node.js. It also provides control over the same. cwd refers to the current working directory of the same. Therefore, process.cwd returns the working directory on which execution is taking place currently.__dirnameThis is a local module that will return the directory ... Read More
Both the methods – console.log and process.stdout.write have a basic definition to write or print the statements on the console. But, there is a slight difference in the way they execute these tasks. Internally, console.log implements process.stdout.write which itself is a buffer stream that will be used to directly print statements on your console.process.stdout.writeconsole.logIt continuously prints information as retrieved from the stream without adding any new line.It first prints the information being retrieved and then adds a new line. Then it will go to retrieve the second set of statements to print.The process.stdout.write method takes only string as paramter. Other ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP