Node.js File System Module

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 The fs.readFile() method is used to read files on your computer. Assume we have the following HTML file (located in the …

Continue Reading

Node.js HTTP Module

he 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. …

Continue Reading

Node.js Modules

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 a complete list of modules. Include Modules To include a module, use …

Continue Reading

Node.js Get Started

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 (req, res) {  res.writeHead(200, {‘Content-Type’: ‘text/html’});  res.end(‘Hello World!’);}).listen(8080); Save the file on your computer: C:\Users\Your …

Continue Reading

Node.js Introduction

What is Node.js? Why Node.js? Node.js uses asynchronous programming! A common task for a web server can be to open a file on the server and return the content to the client. Here is how PHP or ASP handles a file request: Here is how Node.js handles a file request: Node.js eliminates the waiting, and simply continues with the next …

Continue Reading