A collection of basic Node.js examples demonstrating fundamental concepts like HTTP servers, file operations, modules, and URL handling.
- myDateTime.js - A simple module that exports a function returning the current date and time.
-
firstServer.js - Creates a basic HTTP server on port 8080, importing the myDateTime module to display the current date/time.
- Run with:
node firstServer.js - Visit: http://localhost:8080
- Run with:
-
secondServerUrlDemo.js - HTTP server that captures and displays the request URL in the response.
- Run with:
node secondServerUrlDemo.js - Visit: http://localhost:8080/anything/you/want
- Run with:
-
thirdServer.js - Server that parses URL query parameters using the built-in url module.
- Run with:
node thirdServer.js - Example: http://localhost:8080/?year=2023&month=October
- Run with:
-
unknownQueryParams.js - Advanced URL query parameter handling that dynamically processes any parameter names and values.
- Run with:
node unknownQueryParams.js - Example: http://localhost:8080/?name=John&age=30&profession=Developer
- Run with:
-
fourthServer.js - Server that reads an HTML file (demoFile.html) and serves its contents.
- Run with:
node fourthServer.js - Visit: http://localhost:8080
- Run with:
-
fileCreator.js - Demonstrates various file system operations:
- Creating files (appendFile, open, writeFile methods)
- Updating file content
- Renaming files
- Run with:
node fileCreator.js
- demoFile.html - Simple HTML file used by fourthServer.js to demonstrate serving static content.
- Make sure you have Node.js installed.
- Clone this repository.
- Run any example using the Node.js runtime:
node filename.js - For server examples, open your browser to http://localhost:8080
This repository demonstrates:
- Creating and using Node.js modules
- Setting up basic HTTP servers
- Handling URL requests and query parameters
- Reading and serving HTML files
- Performing file system operations (create, write, append, rename)