NODE JS Lab Manual 23-24
NODE JS Lab Manual 23-24
Of
Computer Science and Engineering
Course Outcomes: At the end of the course, the student will be able to,
● Build a custom website with HTML, CSS, and Bootstrap and little JavaScript.
● Demonstrate Advanced features of JavaScript and learn about JDBC
● Develop Server – side implementation using Java technologies like servlet
● Develop the server – side implementation using Node JS.
● Design a Single Page Application using React.
Exercises:
1. Build a responsive web application for shopping cart with registration, login, catalog and cart
pages using CSS3 features, flex and grid.
2. Make the above web application responsive web application using Bootstrap framework.
3. Use JavaScript for doing client – side validation of the pages for the above 2 web applications.
4. Develop a java stand alone application that connects with the database (Oracle / mySql) and
perform the CRUD operation on the database tables.
5. Create an xml for the bookstore. Validate the same using both DTD and XSD.
6. Design a controller with servlet that provides the interaction with web application
7. Maintaining the transactional history of any user is very important. Explore the various session
tracking mechanism using Cookies
8. Maintaining the transactional history of any user is very important. Explore the various session
tracking mechanism using Sessions.
9. Develop an express web application that can interact with REST API to perform CRUD
operations on student data
10. Create a react application for the student management system having registration, login,
contact, about pages and implement routing to navigate through these pages.
11. Create a custom server using http module and explore the other modules of Node JS like OS,
path, event.
Week 1: Build a responsive web application for shopping cart with registration, login, catalog and cart
pages using CSS3 features, flex and grid.
Index.html
<html>
<head>
<title>VJIT</title>
</head>
<frameset rows="20%,*">
<frameset cols="15%,*">
</frameset>
</frameset>
</html>
Home.html
<html>
<head><title>Welcome to VJIT</title>
</head>
<body>
<font color="#448646">
<p>Making a choice of joining VJIT would be one of your best decisions towards building a long
lasting and prolific career. VJIT students will be going through a multi dimensional development
model. The model engages the students into a hub of activities –on the campus training and
development to internships in industry which help them in becoming complete professionals.</p>
<p>VJIT has a consistent placement track record of over 72% placements for the past five years
providing opportunities in some of the best and world class MNCs like Infosys, TCS, Cognizant,
Amazon, CYIENT and others…</p>
</font>
</body>
</html>
Left.html
<html>
<head>
<title> Branches</title>
</head>
<body>
</html>
Right.html
<html>
<head>
</head>
<body>
<font color="green"><p> Welcome to VJIT </p>
</body>
</html>
Top.html
<html>
<head>
</head>
<body style="background-color:#faffff">
</br>
</center>
</body>
</html>
Login.html
<html>
<head>
<title> Login</title>
<head>
<body>
<table align="center">
<caption><b>Login</b></caption>
<tr>
<td>Username</td>
</tr>
<tr>
<td>Password</td>
</tr>
<tr>
</td>
</tr>
</table>
</form>
</body>
</html>
Register.html
<html>
<head>
<title>Register </title>
</head>
<body>
<tr>
<td>User Name</td>
</tr>
<tr>
<td>Password</td>
</tr>
<tr>
<td>E-mail</td>
</tr>
<tr>
<td>Phone Number</td>
</tr>
<tr>
<td>Gender</td>
</tr>
<tr>
<td>Date Of Birth</td>
</tr>
<tr>
<td>Languages Known</td>
</td>
</tr>
<tr>
<td><select name="states">
<option value="Select">SelectState</option>
<option value="Telangana">TS</option>
<option value="AP">AP</option>
<option value="MP">MP</option>
<option value="Karnataka">Karnataka</option>
<option value="Tamilnadu">TN</option>
</select>
</td>
<td><select name="dist">
<option value="Select">SelectDist</option>
<option value="Hyderabad">Hyderabad</option>
<option value="Warangal">Warangal</option>
<option value="RangaReddy">RangaReddy</option>
<option value="Karimnagar">Karimnagar</option>
<option value="Nalgonda">Nalgonda</option>
</select>
</td>
</tr>
<tr>
<td>Address</td>
</tr>
<tr>
</td>
</tr>
</table>
</body>
</html>
Cart.html
<html>
<head>
</head>
<body>
<table>
<tr>
<th>Book Name </th>
<th>Price </th>
<th>Quantity </th>
<th>Amount</th>
</tr>
<tr>
<td>Java 2</td>
<td >$35.5</td>
<td align="center">$70</td>
</tr>
<tr>
<td align="center">$40.5</td>
</tr>
<tr>
<td align="center">$130</td>
</tr>
</table>
</body>
</html>
Catologue.html
<html>
<head>
<title> Catalogue</title>
</head>
<body>
<table>
<tr>
<th>Image </th>
<th>Author </th>
<th>Publisher </th>
<th>Price </th>
<th>Add To Cart</th>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
</body>
</html>
Output:
2. RESPONSIVE SHOPPING CART USING BOOTSTRAP
<h1>Your Cart</h1>
<div class="container-fluid">
<!--1-->
</div>
</div>
<div class="col-2">
</div>
<div class="col-2">
<p id="cartItem1Price">$66</p>
</div>
</div>
<hr>
<!--2-->
</div>
</div>
<div class="col-2">
</div>
<div class="col-2">
<p id="cartItem1Price">$66</p>
</div>
</div>
<hr>
</div>
<h6>Subtotal</h6>
</div>
<p id="subtotal">$132.00</p>
</div>
</div>
<h6>Tax</h6>
</div>
<p id="tax">$6.40</p>
</div>
</div>
<hr>
<h5>Total</h5>
</div>
<p id="total">$138.40</p>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<footer class="container">
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"></script>
OUTPUT:
Your Cart
Dark Art 1
20 x 24
Matte Print
1
$66
Dark Art 2
20 x 24
Matte Print
1
$66
Subtotal
$132.00
Tax
$6.40
Total
$138.40
Week 3: Use JavaScript for doing client – side validation of the pages for the above 2 web
applications.
Program:
<html>
<head>
<title> Registration Page </title>
</head>
<body style="background-color : lightblue">
<h2 align="center"> Registration Page </h2>
<label>Name*</label>
<input type="text" id="nametxt" size="20" ><br><br>
<label>Password*</label>
<input type="text" id="pwdtxt" size="20" ><br><br>
<label>Email*</label>
<input type="text" id="emailtxt" size="30"><br><br>
<label>Phone no*</label>
<input type="text" id="phtxt" size="20" ><br><br>
<label>Gender</label>
<input type="radio" name="gender" id="m" value="m">Male
<input type="radio" name="gender" id="f" value="f">Female <br><br>
<label> Date of Birth</label>
<input type="date" id="bday" ><br><br>
<label> Languages Known </label>
<div class="checkboxgroup" >
<input type="checkbox" name="lang"> English
<input type="checkbox" name="lang"> Telugu
<input type="checkbox" name="lang"> Hindi <br><br>
</div>
<label> Address </label><br>
<textarea rows=5 cols=50 id="addtxtarea" scrolling="yes"></textarea>
</p>
<input type="Submit" value="Register"/>
<script>
function validateForm()
{
var name = document.getElementById("nametxt").value;
var pwd = document.getElementById("pwdtxt").value;
var mobile = document.getElementById("phtxt").value;
var email = document.getElementById("emailtxt").value;
//name validation
if (name.length < 6)
{
alert("The name must be min 6 chars");
return false;
}
//password validation
if (pwd.length < 6)
{
alert("The password must be min 6 chars");
return false;
}
//email validation
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(email.match(filter))
{
}
else
{
alert("Not a valid Email ID");
return false;
}
}
else
{
alert("Not a valid Phone Number");
return false;
}
}
</script>
</form>
</body>
</html>
Success.html
<html>
<body>
<h1> Successfully Registered..</h1>
</body>
</html>
Output:
Week 4: Develop a java stand alone application that connects with the database (Oracle / mySql) and
perform the CRUD operation on the database tables.
import java.sql.*;
class InsertDemo
try
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Statement stmt=con.createStatement();
stmt.executeUpdate(q);
catch(Exception e)
}
Output:
Connection Established
Recorde Inserted
import java.sql.*;
class SelectDemo
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(q);
System.out.println("SID\tName");
while(rs.next())
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2));
System.out.println("");
catch(Exception e)
{
System.out.println("Connection Failed: "+e);
Output:
Connection Established
501 Ravi
502 sharma
import java.sql.*;
class UpdateDemo
try
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Statement stmt=con.createStatement();
stmt.executeUpdate(q);
System.out.println("Record Updated");
catch(Exception e)
Output:
Connection Established
Record Updated
import java.sql.*;
class DelDemo
try
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Statement stmt=con.createStatement();
stmt.executeUpdate(q);
System.out.println("Record Deleted");
catch(Exception e)
Output:
Connection Established
Record Deleted
Week 5: Create an xml for the bookstore. Validate the same using both DTD and XSD.
Programs:
Lab.dtd
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT books (book*)>
<!ELEMENT book (title, author, isbn, publisher, edition, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
Bookstab.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bookstab SYSTEM "lab.dtd">
<?xml-stylesheet type="text/xsl" href="books.xsl"?>
<books>
<book>
<title>Programming the World Wide Web</title>
<author>Robert W. Sebesta</author>
<isbn>1234-5678</isbn>
<publisher>Tata McGraw-Hill</publisher>
<edition>Seventh</edition>
<price>300</price>
</book>
<book>
<title>Web Technologies</title>
<author>Uttam K Roy</author>
<isbn>2345-1234</isbn>
<publisher>Oxford University Press</publisher>
<edition>First</edition>
<price>350</price>
</book>
<book>
<title>The Complete Reference PHP</title>
<author>Steven Holzner</author>
<isbn>4567-8970</isbn>
<publisher>Tata McGraw-Hill</publisher>
<edition>Second</edition>
<price>500</price>
</book>
<book>
<title>Java Script</title>
<author>D Flanagan</author>
<isbn>1234-9876</isbn>
<publisher>Tata</publisher>
<edition>Second</edition>
<price>350</price>
</book>
<book>
<title>Web Programming, Building Internet Applications , 2nd edition , Wiley</title>
<author>Chris Bates</author>
<isbn>3456-8976</isbn>
<publisher>Wiley</publisher>
<edition>Second</edition>
<price>240</price>
</book>
</books>
Output:
SchemaEmp.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.eswar.com"
xmlns="http://www.eswar.com"
elementFormDefault="qualified">
<xs:element name="emp">
<xs:complexType>
<xs:sequence>
<xs:element name="empno" type="xs:int"/>
<xs:element name="empname" type="xs:string"/>
<xs:element name="empsal" type="xs:decimal" />
<xs:element name="dept" type="xs:string" fixed="IT"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
SchemaEmp.xml
<?xml version="1.0" encoding="UTF-8"?>
<emp xmlns="http://www.eswar.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eswar.com SchemaEmp.xsd">
<empno>1201</empno>
<empname>eswar</empname>
<empsal>300.50</empsal>
<dept>IT</dept>
</emp>
Output:
Week 6: Design a controller with servlet that provides the interaction with web application
Database :2018
Table Name:registration
Programs:
Registration.html
<html>
<head>
<title> Registration Page </title>
</head>
<body style="background-color : lightblue">
<h2 align="center"> Registration Page </h2>
<form name="myForm" method="post" action="Register">
<label>Name*</label>
<input type="text" id="nametxt" name="nametxt" size="20" ><br><br>
<label>Password*</label>
<input type="password" id="pwdtxt" name="pwdtxt" size="20" ><br><br>
<label>Email*</label>
<input type="text" id="emailtxt" name="emailtxt" size="30"><br><br>
<label>Phone no*</label>
<input type="text" id="phtxt" name="phtxt" size="20" ><br><br>
<label>Gender</label>
<input type="radio" name="gender" id="m" value="m">Male
<input type="radio" name="gender" id="f" value="f">Female <br><br>
<label> Date of Birth</label>
<input type="date" id="bday" name='dob' ><br><br>
<label> Languages Known </label>
<div class="checkboxgroup" >
<input type="checkbox" name="lang[]" value="English"> English
<input type="checkbox" name="lang[]" value="Telugu"> Telugu
<input type="checkbox" name="lang[]" value="Hindi"> Hindi <br><br>
</div>
<label> Address </label><br>
<textarea rows=5 cols=50 id="addtxtarea" name= "addtxtarea" scrolling="yes"></textarea>
<br><br>
<input type="Submit" value="Register"/>
</form>
</body>
</html>
RegisterApp2018.java
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
// Extend HttpServlet class
public class RegisterApp2018 extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException
{
response.setContentType("text/html");
String fn=request.getParameter("nametxt");
String pw=request.getParameter("pwdtxt");
String ei=request.getParameter("emailtxt");
String pn=request.getParameter("phtxt");
String dob=request.getParameter("dob");
String g=request.getParameter("gender");
String add=request.getParameter("addtxtarea");
String[] la=request.getParameterValues("lang[]");
String lang = String.join(", ", la);
PrintWriter out = response.getWriter();
out.println("<h1>Registration Details</h1><br>");
out.println("<b>First Name</b>:" + fn + "<br>");
out.println("<b>Email</b>:"+ ei + "<br>");
out.println("<b>Password</b>:" + pw + "<br>");
out.println("<b>Phone Number</b>:" +pn + "<br>");
out.println("<b>Gender</b>:" + g + "<br>");
out.println("<b>DOB</b>:" + dob + "<br>");
out.println("<b>Languages Known</b>:" + lang +"<br>");
out.println("<b>Address </b>:" + add);
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/2018","root","");
String sql="INSERT INTO registration VALUES(?,?,?,?,?,?,?,?)";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString (1,fn);
pst.setString (2,pw);
pst.setString (3,ei);
pst.setString (4,pn);
pst.setString (5,g);
pst.setString (6,dob);
pst.setString (7,lang);
pst.setString (8,add);
pst.execute();
out.println("<br>Record inserted successfully.. Registration was
completed...</body></html>");
con.close();
}
catch(Exception e)
{
out.println(e);
}
}
}
Web.xml
<web-app>
<servlet>
<servlet-name>Reg</servlet-name>
<servlet-class>RegisterApp2018</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Reg</servlet-name>
<url-pattern>/Register</url-pattern>
</servlet-mapping>
</web-app>
Output:
Week 7: Maintaining the transactional history of any user is very important. Explore the various
session tracking mechanism using Cookies
i) Cookies – Programs
CookiesDemo.html
<html>
<body>
<form action = "CookiesDemo" method = "GET">
First Name: <input type = "text" name = "first_name">
<br><br>
Last Name: <input type = "text" name = "last_name" />
<br><br>
<input type = "submit" value = "Submit" />
</form>
</body>
</html>
CookiesDemo.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
ReadCookiesDemo.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
}
}
Web.xml
<web-app>
<servlet>
<servlet-name>cookies</servlet-name>
<servlet-class>CookiesDemo</servlet-class>
</servlet>
<servlet>
<servlet-name>cookies1</servlet-name>
<servlet-class>ReadCookiesDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cookies</servlet-name>
<url-pattern>/CookiesDemo</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>cookies1</servlet-name>
<url-pattern>/ReadCookiesDemo</url-pattern>
</servlet-mapping>
</web-app>
Output:
Week 8: Maintaining the transactional history of any user is very important. Explore the various
session tracking mechanism using Sessions.
HttpSession – Programs
SessionTrack.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
Web.xml
<web-app>
<servlet>
<servlet-name>Session1</servlet-name>
<servlet-class>SessionTrack</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Session1</servlet-name>
<url-pattern>/SessionTrack</url-pattern>
</servlet-mapping>
</web-app>
Output:
Week 9: Develop an express web application that can interact with REST API to perform CRUD
operations on student data
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
2. Project Structure
Refer to the below screenshot to create a project structure or a packing structure for our Spring boot
application
spring.datasource.url=jdbc:mysql://localhost:3306/user_management
spring.datasource.username=root
spring.datasource.password=Mysql@123
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=update
Don’t forget to change the spring.datasource.username and spring.datasource.password as per
your MySQL installation. Also, create a database named user_management in MySQL before
proceeding to the next section.
You don’t need to create any tables. The tables will automatically be created by Hibernate from
the User entity that we will define in the next step. This is made possible by the
property spring.jpa.hibernate.ddl-auto = update.
Let's create a User JPA entity class with the following fields:
● id - primary key
● firstName - user first name
● lastName - user last name
● email - user email ID
package net.javaguides.springboot.entity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String firstName;
@Column(nullable = false)
private String lastName;
@Column(nullable = false, unique = true)
private String email;
}
Note that we are using Lombok annotations to reduce the boilerplate code such as getter/setter
methods, and constructors.
We are using below JPA annotations to map an Entity with a database table:
@Table annotation is used to provide the details of the table that this entity will be mapped to.
@GeneratedValue annotation is used to define the primary key generation strategy. In the above
case, we have declared the primary key to be an Auto Increment field.
@Column annotation is used to define the properties of the column that will be mapped to the
annotated field. You can define several properties like name, length, nullable, updateable, etc.
Well, Spring Data JPA comes with a JpaRepository interface that defines methods for all the
CRUD operations on the entity, and a default implementation
of JpaRepository called SimpleJpaRepository.
package net.javaguides.springboot.repository;
import net.javaguides.springboot.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
UserService Interface
package net.javaguides.springboot.service;
import net.javaguides.springboot.entity.User;
import java.util.List;
List<User> getAllUsers();
package net.javaguides.springboot.service.impl;
import lombok.AllArgsConstructor;
import net.javaguides.springboot.entity.User;
import net.javaguides.springboot.repository.UserRepository;
import net.javaguides.springboot.service.UserService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Service
@AllArgsConstructor
public class UserServiceImpl implements UserService {
@Override
public User createUser(User user) {
return userRepository.save(user);
}
@Override
public User getUserById(Long userId) {
Optional<User> optionalUser = userRepository.findById(userId);
return optionalUser.get();
}
@Override
public List<User> getAllUsers() {
return userRepository.findAll();
}
@Override
public User updateUser(User user) {
User existingUser = userRepository.findById(user.getId()).get();
existingUser.setFirstName(user.getFirstName());
existingUser.setLastName(user.getLastName());
existingUser.setEmail(user.getEmail());
User updatedUser = userRepository.save(existingUser);
return updatedUser;
}
@Override
public void deleteUser(Long userId) {
userRepository.deleteById(userId);
}
}
Let's create the REST APIs for creating, retrieving, updating, and deleting a User:
package net.javaguides.springboot.controller;
import lombok.AllArgsConstructor;
import net.javaguides.springboot.entity.User;
import net.javaguides.springboot.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@AllArgsConstructor
@RequestMapping("api/users")
public class UserController {
PROGRAM:
const db = require('./db/database').createDatabase();
require('./startup/db').init(db);
require('./startup/logger')(app);
require('./startup/routers')(app);
require('./startup/swagger')(app);
});
process.on('SIGINT', () => {
server.close(() => {
db.close();
console.log("Server shutdown");
});
});
"name": "cms",
"version": "0.0.1",
"main": "index.js",
"scripts": {
},
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"ejs": "^2.6.1",
"express": "^4.16.4",
"fs": "0.0.1-security",
"joi": "^14.3.1",
"morgan": "^1.9.1",
"sqlite3": "^4.0.6",
"swagger-jsdoc": "^3.2.9",
"swagger-ui-express": "^4.0.2"
},
"devDependencies": {
"nodemon": "^1.18.11"
"name": "cms",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity":
"sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/
1RtehkszU9qcTii0Q=="
},
"accepts": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
"integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=",
"requires": {
"mime-types": "~2.1.18",
"negotiator": "0.6.1"
}
},
"ajv": {
"version": "6.10.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz",
"integrity": "sha512-
nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYw
YVIIH1TvE3tu4OEg==",
"requires": {
"fast-deep-equal": "^2.0.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
},
"ansi-align": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-2.0.0.tgz",
"integrity": "sha1-w2rsy6VjuJzrVW82kPCx2eNUf38=",
"dev": true,
"requires": {
"string-width": "^2.0.0"
},
"dependencies": {
"ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=",
"dev": true
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-
2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha512-
nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwd
feZ7w7aCvJD7ugkw==",
"dev": true,
"requires": {
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0"
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
},
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity":
"sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCt
OVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
},
"anymatch": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz",
"integrity":
"sha512-5teOsQWABXHHBFP9y3skS5P3d/WfWXpv3FUpy+LorMrNYaT9pI4oLMQX7jzQ2
KklNpGpWHzdCXTDT2Y3XGlZBw==",
"dev": true,
"requires": {
"micromatch": "^3.1.4",
"normalize-path": "^2.1.1"
},
"dependencies": {
"normalize-path": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz",
"integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=",
"dev": true,
"requires": {
"remove-trailing-separator": "^1.0.1"
},
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
"integrity":
"sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcB
o03Hi3jMxigBtsddlXRw=="
},
"are-we-there-yet": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz",
"integrity": "sha512-
5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJ
nl3j2kpBan13PtQf6w==",
"requires": {
"delegates": "^1.0.0",
"readable-stream": "^2.0.6"
let db;
module.exports.createDatabase = () => {
});
return db;
// create a server
http.createServer(function (req, res) {
// code to feed or request and prepare response
}).listen(9000); //the server object listens on port 9000
Step 3 : Prepare response
We shall prepare a response with HTTP header and a message.
// include http module in the file
var http = require('http');
// create a server
http.createServer(function (req, res) {
// http header
// 200 - is the OK message
// to respond with html content, 'Content-Type' should be 'text/html'
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Node.js says hello!'); //write a response to the client
res.end(); //end the response
}).listen(9000);
Step 4 : Run the Web Server
Run the httpWebServer.js file (from previous step) to create and make the server listen at port
9000.
node httpWebServer.js
The server will be up and running.
Step 5 : Test the Web Server