0% found this document useful (0 votes)
8 views8 pages

MERN Lab Programs

The document outlines three programming tasks for a Full Stack Web Development course at KLE Technological University, focusing on Node.js applications. The first task involves creating a student course registration system, the second is an employee record management system, and the third is a large file processing system using streams. Each task includes specific requirements and example code to demonstrate the implementation of file operations and data handling.

Uploaded by

neelammanmathk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

MERN Lab Programs

The document outlines three programming tasks for a Full Stack Web Development course at KLE Technological University, focusing on Node.js applications. The first task involves creating a student course registration system, the second is an employee record management system, and the third is a large file processing system using streams. Each task includes specific requirements and example code to demonstrate the implementation of file operations and data handling.

Uploaded by

neelammanmathk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

KLE TECHNOLOGICAL

UNIVERSITY

Full Stack Web Development using MERN


Journal Programs
2024-2027 Batch

DEPARTMENT OF MASTER OF COMPUTER


APPLICATIONS KLE TECHNOLOGICAL UNIVERSITY
Vidyanagar, Hubballi-580031, Karnataka.
Program 1:

Implement Student Course Registration with the following details using [Link]

 Create a file for all the courses with course name, course code, LTP model and credits.
 Display the file content on the web browser using HTTP module.

Code:
Program 2:

Employee Record Management System

Scenario

A company wants to store and manage employee records in a file using [Link].

Task

Write a [Link] program that performs the following file system operations:

1. Create a file [Link] and store employee details.

2. Write employee data into the file.

3. Append new employee records to the same file.

4. Read the file synchronously and display the employee data.

5. Read the file asynchronously and display the employee data.

6. Open the file and display a message when it opens successfully.

7. Delete the file after displaying the records.

Code:

// Import File System module

const fs = require("fs");

// Employee data

const employeeData = "Employee ID: 101\nName: \nDepartment: IT\n";

const newEmployee = "Employee ID: 102\nName: \nDepartment: HR\n";

// 1. Create file and write employee data

[Link]("[Link]", employeeData);

[Link]("File created and employee data written");

// 2. Append new employee record

[Link]("[Link]", newEmployee);

[Link]("New employee record appended");

// 3. Read file synchronously

const dataSync = [Link]("[Link]", "utf8");


[Link]("\nSynchronous Read:");

[Link](dataSync);

// 4. Read file asynchronously

[Link]("[Link]", "utf8", (err, data) => {

if (err) {

[Link](err);

return;

[Link]("\nAsynchronous Read:");

[Link](data);

// 5. Open the file

[Link]("[Link]", "r", (err, fd) => {

if (err) {

[Link](err);

return;

[Link]("\nFile opened successfully");

// 6. Delete the file

[Link]("[Link]", (err) => {

if (err) {

[Link](err);

return;

[Link]("File deleted successfully");

});
});

});

Output:

File created and employee data written

New employee record appended

Synchronous Read:

Employee ID: 101

Name:

Department: IT

Employee ID: 102

Name: Rahul

Department: HR

Asynchronous Read:

Employee ID: 101

Name:

Department: IT

Employee ID: 102

Name: Rahul

Department: HR

File opened successfully

File deleted successfully


Program 3:

Large File Processing System

Scenario

A media company needs to process large log files efficiently without loading the entire file into
memory.

Task

Write a [Link] program that performs the following stream operations:

1. Use a readable stream to read data from [Link].

2. Use a writable stream to write the data into [Link].

3. Use piping to copy data from [Link] to [Link].

4. Use stream chaining to compress the file into [Link].

5. Use a decompress stream to unzip the compressed file.

Code:

// Import required modules

const fs = require("fs");

const zlib = require("zlib");

// 1. Create a readable stream to read data from [Link]

const readStream = [Link]("[Link]", "utf8");

// Display data chunks while reading

[Link]("data", (chunk) => {

[Link]("Reading chunk:");

[Link](chunk);

});

// 2. Create a writable stream to write data into [Link]

const writeStream = [Link]("[Link]");

// 3. Use piping to copy data from [Link] to [Link]

[Link](writeStream);
[Link]("Data is being copied using pipe...");

// 4. Use stream chaining to compress the file into [Link]

[Link]("[Link]")

.pipe([Link]())

.pipe([Link]("[Link]"));

[Link]("File compressed successfully");

// 5. Decompress the compressed file

[Link]("[Link]")

.pipe([Link]())

.pipe([Link]("logfile_uncompressed.txt"));

[Link]("File decompressed successfully");

You might also like