Department of Computing: Instructor: Dr. Sidra Sultana Lab Engineer: Ms. Ayesha Asif
Department of Computing: Instructor: Dr. Sidra Sultana Lab Engineer: Ms. Ayesha Asif
Introduction
This lab is about the installation and introduction to node.js environment. Node.js is an open
source server environment. It runs on various platforms (Windows, Linux, Unix, Mac OS X,
etc.). Node.js uses JavaScript on the server.
A common task for a web server can be to open a file on the server and return the content to the
client.
Objectives
This lab will get you familiar with the node.js environment.
Tools/Software Requirement
Node.js, Notepad
Description
Helping Material
https://www.w3schools.com/nodejs/nodejs_get_started.asp
Lab Tasks
Task 1: Download Node.js from the official Node.js web site: https://nodejs.org.
Task 2: Once you have downloaded and installed Node.js on your computer, let's try to display
"Hello World" in a web browser.
Hint:
Create a Node.js file named "myfirst.js", and add the code.
Save the file on your computer: C:\Users\Your Name\myfirst.js
The file you have just created must be initiated by Node.js before any action can take place.
Start your node.js command line interface, write node myfirst.js and hit enter
Task 4: Use the module "myfirstmodule" of date and time in a Node.js file.
Task 5: 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.
Hint: If the response from the HTTP server is supposed to be displayed as HTML, you should
include an HTTP header with the correct content type like:
res.writeHead(200, {'Content-Type': 'text/html'});
The first argument of the res.writeHead() method is the status code, 200 means that all is OK, the
second argument is an object containing the response headers.
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');
Read files
Create files
Update files
Delete files
Rename files
Task 7: Create a Node.js file that reads the HTML file, and return the content.
Solution
Task Code:
Deliverables
Compile a single word document by filling in the solution part and submit this Word file on
LMS. This lab grading policy is as follows: The lab is graded between 0 to 10 marks. The
submitted solution can get a maximum of 5 marks. At the end of each lab or in the next lab, there
will be a viva related to the tasks. The viva has a weightage of 5 marks. Insert the
solution/answer in this document. You must show the implementation of the tasks in the
designing tool, along with your complete Word document to get your work graded. You must
also submit this Word document on the LMS. In case of any problems with submissions on
LMS, submit your Lab assignments by emailing it to Ms. Ayesha Asif:
[email protected].