View all #

What is a Module in Node.js? Consider modules to be the same as JavaScript libraries. A set of functions you want to include in your application. Built-in Modules Node.js has a set of built-in modules which you can use without any further installation. Look at our Built-in Modules Reference for […]

Node.js as a File Server The Node.js file system module allows you to work with the file system on your computer. To include the File System module, use the require() method: var fs = require(‘fs’); Common use for the File System module: Read files Create files Update files Delete files […]

The Built-in URL Module The URL module splits up a web address into readable parts. To include the URL module, use the require() method: var url = require(‘url’); Parse an address with the url.parse() method, and it will return a URL object with each part of the address as properties: […]

The Nodemailer Module The Nodemailer module makes it easy to send emails from your computer. The Nodemailer module can be downloaded and installed using npm: C:UsersYour Name>npm install nodemailer After you have downloaded the Nodemailer module, you can include the module in any application: var nodemailer = require(‘nodemailer’); Send an […]

  Node.js can be used in database applications. One of the most popular databases is MySQL. MySQL Database To be able to experiment with the code examples, you should have MySQL installed on your computer. You can download a free MySQL database at https://www.mysql.com/downloads/. Install MySQL Driver Once you have […]

Creating a Database To create a database in MySQL, use the “CREATE DATABASE” statement: Example Create a database named “mydb”: var mysql = require(‘mysql’);var con = mysql.createConnection({ host: “localhost”, user: “yourusername“, password: “yourpassword” }); con.connect(function(err) { if (err) throw err; console.log(“Connected!”); con.query(“CREATE DATABASE mydb“, function (err, result) { if (err) […]

What is Node.js? Node.js is an open source server environment Node.js is free Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) Node.js uses JavaScript on the server Why Node.js? Node.js uses asynchronous programming! A common task for a web server can be to open a file […]

Download Node.js The official Node.js website has installation instructions for Node.js: https://nodejs.org Getting Started Once you have downloaded and installed Node.js on your computer, let’s try to display “Hello World” in a web browser. Create a Node.js file named “myfirst.js”, and add the following code: myfirst.js var http = require(‘http’);http.createServer(function […]

Node.js is perfect for event-driven applications. Events in Node.js Every action on a computer is an event. Like when a connection is made or a file is opened. Objects in Node.js can fire events, like the readStream object fires events when opening and closing a file: Example var fs = […]

What is NPM? NPM is a package manager for Node.js packages, or modules if you like. www.npmjs.com hosts thousands of free packages to download and use. The NPM program is installed on your computer when you install Node.js NPM is already ready to run on your computer! What is a […]