PW_Assignment_Web_dev_Nodejs

Q1. In this coding challenge, your task is to create a package&json file for your project using the npm init command& The package&json file is essential for managing dependencies, scripts, and other project"related details& Below is the expected folder structure.

Solution.

create a folder Nodejs.

goto the terminal and type the command npm init.

Q2 In t.he same project directory created in the above assignment, your task is to create a new file index&js and using the fs module add information about Node&js architecture to a new file nodejs_architecture&txt& Below are the expected files in the project folder.

Solution.

create one more folder in NodeJs folder called fs

in fs folder create an index.js file and node_Architecture.txt

Q3.Continuing assignment 2& Here, let’s create a new file named index&js and use the fs module to read the content of nodejs_architecture&txt and print the content to the console.

Solution: In the node_architecture file read the architecture of nodejs.

goto to the index.js file write the code given in the below

reference geek for geeks.

Q.4In this coding challenge, you will continue working with the file created in the previous assignments& Here your task is to access the existing nodejs_architecture&txt file and use the fs module to append additional data to it& Specifically, add some advantages of Node&js to the file and print the file content to the console.

solution: write code as given in below

fs.appendFile('pathname', "text", function());

Q5.To wind up the fs module walk"through challenges, let’s delete the nodejs_architecture&txt file& On deletion print "File Deleted SuccessFully" to the console.

Solution: for delete

fs.unlink('path', function());

Q6.Assume a situation where our server restricts access to its configuration via the user interface& The only way to obtain the OS and release information is through a programmatic approach& In this challenge, you are expected to use the os module and print the os name and the os"release version to the console.

solution: const os = require('os')

console.log(os.release());

console.log(os.type())

Q.7 In this challenge, you are required to use Node1js and the built-in HTTP module to create a server that displays the text "I Am Happy To Learn Full Stack Web Development From PW Skills!" on the browser screen1 The goal is to utilize the HTTP module to create an HTTP server, set the port, appropriate content type, and send the message as a response to the client's request, allowing it to display on the browser1

Q.8 Let's simulate a subscription feature similar to YouTube1 Using the events module, we'll create a custom event named "subscribe"1 When this event is triggered, it should display a message in the console indicating that the user has subscribed1