Conteúdo do Curso
Backend Development with Node.js and Express.js
Backend Development with Node.js and Express.js
1. Introduction to Node.js and Backend Development
2. Building Console Applications with Node.js
Introduction to Console Applications in Node.jsWhat are Console Applications?Working with the File System in Node.jsChallenge: File System OperationsBuilding Command Line Interface (CLI) AppsUsing the Commander Module for CLI AppsWorking with the Readline ModuleBuilding a Guessing Game Console AppManaging Directories in Node.jsDirectory Inspection ToolSummary of Console Applications in Node.js
3. Developing Web Applications with Express.js
Introduction to Express.js in Web DevelopmentWhy Use Express.js for Web Development?Understanding HTTP RequestsSetting Up an Express.js ApplicationCreating and Managing Routes in Express.jsTesting APIs with PostmanIntroduction to Middleware in Express.jsUsing Built-in Middleware in Express.jsCreating Custom MiddlewareSummary of Key Express.js Concepts
4. Building REST APIs with Node.js and Express.js
Introduction to REST API DevelopmentCore Concepts of REST APIsSetting Up the Project StructureDefining the Entry Point of the APIBuilding the GET All Posts EndpointBuilding the GET Post by Id EndpointBuilding the CREATE Post EndpointBuilding the UPDATE Post by Id EndpointBuilding the DELETE Post by Id EndpointRunning and Testing the REST APIFinal Thoughts and Next Steps
Challenge: File System Operations
🏆 Challenge
🎯 Goal
Master the art of task management automation! Your mission is to develop an application that gathers tasks from one source, extracts their content, and integrates them into another file. Your solution should also handle any potential errors along the way.
📋 Task
Imagine you have two files: tasks.txt
, which contains a list of existing tasks, and new-task.txt
, which includes a single task that must be added to the tasks.txt
file.
Follow these steps to complete the challenge and create the real deal on your machine:
- Prepare Your Workspace: Start by creating a new folder on your machine and open it using your favorite code editor.
- Setup Tasks: Create the
tasks.txt
file and populate it with the following tasks or use the provided tasks.txt file:Teach a goldfish 🐠 to play chess ♟️
;Build a sandcastle 🏰 in your living room 🛋️
;Create a song 🎶 using only sounds from nature 🌿
.
- Define New Task: Create the
new-task.txt
file and insert the following task or use the provided new-task.txt file:Invent a new dance move and perform it in public. 💃🕺
.
- Main Script: Craft the
app.js
file, which will serve as the heart of your application.- Import fs Module: Begin by importing the
fs
module to enable file handling within your application; - Read Content: Utilize the
readFile
function from thefs
module to extract the content from thenew-task.txt
file. Be sure to implement.then()
and.catch()
to manage both success and error scenarios; - Append Content: Inside the
.then()
block, once the content is successfully read, employ theappendFile
function to add the content to thetasks.txt
file. Don't forget to append a newline character (\n
) after the content.
- Import fs Module: Begin by importing the
- Run the Magic: Save your
app.js
file and execute it using Node.js in the terminal with the commandnode app
.
If you prefer to use the code editor below, keep in mind that it does not recognize your files and will not show your progress.
const fs = require("fs").___; fs.___("new-task.txt", "utf-8") .then(___ => { return fs.___("tasks.txt", ___ + ___); }) .___((error) => { console.log("Error:", error); });
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 2. Capítulo 4