02:00:00
SENK-012 - '));//Lecture 5----Creating a Simple Server//// Server-side code for a simple application that listens for HTTP requests and returns a simple response.//// The server will listen on port 3000 and return a file when a request is made to the '/file' path.//// The server will also return a message when a request is made to the '/message' path.//// The server will return a 404 error when a request is made to a path that does not exist.//// Code://// server.js//// const http = require('http');// const fs = require('fs');//// const server = http.createServer((req, res) => {// if(req.url === '/file' || req.url === '/file'){// res.statusCode = 200;// res.end('This is a file');// }// if(req.url === '/message' or req.url === '/message'){// res.statusCode = 200;// res.end('This is a message');// }// res.statusCode = 404;// res.end('This is a 404');// });//// server.listen(3000, () => {// console.log('server is running on port 3000');// });//// The server will handle requests from a client and send a response to that client.//// The server will store the data in a file and use that file to send a response to the client.//// The server will use the following logic to handle a request://// 1. If the request is for a file, then the server will read the file and send the content to the client.//// 2. If the request is for a message, then the server will read the message and send the content to the client.//// 3. If the request is for something else, then the server will send a 404 error to the client.//// The server will also use the following logic to store data in a file://// 1. If the request is for a file, then the server will write the content to the file.//// 2. If the request is for a message, then the server will write the content to the file.//// 3. If the request is for something else, then the server will send a 404 error to the client.//// 200 � y //Lecture 6----Creating simple web server with NodeJS//// The server will listen on port 3000 and return a file when a request is made to the '/file' path.//// The server will also return a message when a request is made to the '/message' path.//// The server will return a 404 error when a request is made to a path that does not exist.//// Code://// server.js//// const http = require('http');// const fs = require('fs');//// const server = http.createServer((req, res) => {// if(req.url === '/file' || req.url === '/file'){// res.statusCode = 200;// res.end('This is a file');// }// if(req.url === '/message' or req.url === '/message'){// res.statusCode = 200;// resend('This is a message');// }// res.statusCode = 404;// res.end('This is a 404');// });//// server.listen(3000, () => {// console.log('server is running on 3000');// });//// The server will handle requests from a client and send a response to that client.//// The server will store the data in a file and use that file to send a response to the client.//// The server will use the following logic to handle a request://// 1. If the request is for a file, then the server will read the file and send the content to the client.//// 2. If the request is for a message, then the server will read the message and send the content to the client.//// 3. If the request is for something else, then the server will send a 404 error to the client.//// The server will also use the following logic to store data in a file://// 1. If the request is for a file, then the server will write the content to the file.//// 2. If the request is for a message, then the server will write the content to the file.//// 3. If the request is for something else, then the server will send a 404 error to the client.////
2 Jul 2022