This project explores the foundational concepts of Node.js, focusing on practical tasks that demonstrate the use of core Node.js features, Express.js, and related tools. The project covers executing JavaScript in Node.js, handling HTTP requests, reading files, and setting up a small HTTP server, both with Node's HTTP module and Express.
By the end of this project, you should be able to:
- Run JavaScript using Node.js.
- Utilize Node.js modules effectively.
- Read files using specific Node.js modules.
- Access command line arguments and environment variables using the
processobject. - Create HTTP servers using both Node.js and Express.
- Implement advanced routing with Express.
- Use ES6 features in Node.js with Babel.
- Develop more efficiently using Nodemon.
The project is organized into multiple tasks, each focusing on a specific aspect of Node.js and Express.js:
File: 0-console.js
A simple function displayMessage is implemented to print a message to the console using Node.js.
File: 1-stdin.js
A command-line application prompts the user for their name and displays it. The application demonstrates how to handle user input and graceful termination messages.
File: 2-read_file.js
A function countStudents reads a CSV file synchronously and logs the total number of students and students per field.
File: 3-read_file_async.js
This task is similar to the previous one but uses asynchronous file reading to avoid blocking the event loop.
File: 4-http.js
A basic HTTP server is set up to respond with "Hello Holberton School!" for any request.
File: 5-http.js
The server is extended to handle different routes, including a /students route that displays student information from a CSV file.
File: 6-http_express.js
An Express.js server is set up, responding with "Hello Holberton School!" at the root endpoint.
File: 7-http_express.js
The Express server handles multiple routes, including a dynamic route for displaying students by major.
Directory: full_server/
A full-fledged server setup using Express, with organized directories for controllers and routes. It includes:
- Controllers: Handles logic for different endpoints.
AppController.js: Handles the root route.StudentsController.js: Manages routes related to student data.
- Routes: Defines routing logic.
index.js: Connects endpoints to their respective controllers.
- Utilities:
utils.js: Contains helper functions likereadDatabasefor reading student data.
-
Install Dependencies:
npm install
-
Running the Server:
npm run dev
This command uses
nodemonandbabel-nodeto run the server with ES6 support. -
Testing and Linting:
- Run tests:
npm run test - Lint code:
npm run lint
- Run tests:
Please follow the project's coding standards, ensuring that all contributions pass linting and tests.