Tag - Node

How to send an email in Node.js?

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:\Users\Your 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 Email Now you are ready to send emails from your server. Use the username and password from your selected email provider to send an email. This tutorial will show you how to use your Gmail account to send...

Read more...

How Node.js Upload Files?

The Formidable Module There is a very good module for working with file uploads, called "Formidable". The Formidable module can be downloaded and installed using NPM:C:\Users\Your Name>npm install formidable After you have downloaded the Formidable module, you can include the module in any application:var formidable = require('formidable'); Upload Files Now you are ready to make a web page in Node.js that lets the user upload files to your computer: Step 1: Create an Upload Form Create a Node.js file that writes an HTML form, with an upload...

Read more...

What are Node.js Events?

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 = require('fs');var rs = fs.createReadStream('./demofile.txt');rs.on('open', function () {  console.log('The file is open');}); Events Module Node.js has a built-in module, called "Events", where you can create-, fire-, and listen for- your own events. To include the built-in Events module use the require() method. In addition,...

Read more...

What is NPM in Node.js?

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 Package? A package in Node.js contains all the files you need for a module. Modules are JavaScript libraries you can include in your project. Download a Package Downloading a package is very easy. Open the command line interface and tell...

Read more...

What is Node.js HTTP Module?

The Built-in HTTP Module Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP). To include the HTTP module, use the require() method:var http = require('http'); Node.js as a Web Server The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client. Use the createServer() method to create an HTTP server: Example var http = require('http'); //create a server object:http.createServer(function (req, res) {  res.write('Hello World!'); //write a response to the client  res.end(); //end the response}).listen(8080); //the server...

Read more...