Posts

Showing posts from July, 2024

NodeJs 2nd Class

 Sure, let's go through each concept with examples: Nodemon Module Concept Nodemon is a tool that helps develop Node.js based applications by automatically restarting the application when file changes are detected in the directory. Installation: npm install -g nodemon Usage: Instead of running your app with `node app.js`, you can run it with: nodemon app.js Nodemon will automatically restart your server whenever you make changes to your files. URL Module The URL module splits up a web address into readable parts. Example: const url = require('url'); const address = 'http://example.com:8080/default.htm?year=2023&month=july'; const parsedUrl = url.parse(address, true); console.log(parsedUrl.host); // 'example.com:8080' console.log(parsedUrl.pathname); // '/default.htm' console.log(parsedUrl.search); // '?year=2023&month=july' const queryData = parsedUrl.query; console.log(queryData.year); // '2023' console.log(queryData.month);

NodeJS and Introduction

 Here's an introduction to Node.js, Express, MongoDB, and some basic concepts along with examples: Introduction to Node.js Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to run JavaScript on the server side. Event-driven, non-blocking I/O model: Ideal for building scalable network applications. Package ecosystem (npm): Largest ecosystem of open source libraries in the world. Basic Ideas on Node.js Asynchronous: Node.js is designed for asynchronous operations, meaning it can handle many operations at the same time without waiting for any to complete. Single-threaded: Uses a single thread to handle requests, but can handle many concurrent connections efficiently due to its event-driven architecture. Express.js Express.js is a minimal and flexible Node.js web application framework that provides robust features to build single and multi-page, and hybrid web applications. Middleware: Functions that execute during the lifecycle of a request to t