DEV Community

Cover image for Week 1: My first steps into Backend Development 🌐
Nikhil Sharma
Nikhil Sharma

Posted on

Week 1: My first steps into Backend Development 🌐

This week I had no classes in college, so I spent around 20 hours getting my concepts right! Let's delve deeper into everything I covered during the week.

Learning the Basics🔄

I took my first few steps in full stack web development which started with learning the fundamentals of HTTP protocols. I set up my first server using Express.js and at first it was just understanding the syntax, and learning about endpoints and whatnot. Seeing the "get" request running successfully in Postman gave me a huge boost.

Understanding CRUD🚀

After getting comfortable with endpoints, I dug deeper and discovered different types of HTTP requests - CRUD.

  • GET - To fetch data from the backend.
  • POST - To add new data to the backend.
  • PUT - To update data in the backend.
  • DELETE - To delete data from the backend.

This was a real eye-opener, because these are the backbone of all websites. I was surprised when I realised that using these requests and an HTTP server written in Express.js, I had basically made my own API.

📝Assignments of the Week

After the basics, I jumped into my assignments for the week.

1. A basic file management server

  • #### Question statement- I had to create an Express.js HTTP server in Node.js which would handle the logic of a file server. It had to have two endpoints
    • GET "/files/"- which would return the names of all files present in './files/' directory(no database logic for now).
    • GET "/files/:filename/"- which would return all the contents of the file in the request path parameter.
  • #### 💡New things I picked up
    • Using ‘fs’ which is Node.js’s built-in File system module(helps perform CRUD and more on files)
    • How request parameters work! And how to grab them and store them in a variable.
const filename = req.params.filename;
Enter fullscreen mode Exit fullscreen mode

2. An express HTTP server in Node.js which will handle the logic of a todo list app

  • #### Question statement- Had to create a todo app which would have the following endpoints and functions
    • GET "/todos/"- which would return all todos which are stored locally
    • GET "/todos/:id"- which would return todo with id specified in the request parameters
    • POST "/todos/"- which would let the user add a new todo item
    • PUT "/todos/:id"- which would let the user mark the specified todo as done
    • DELETE "/todos/:id"- which would let the user delete the specified todo
  • 💡New things I picked up

    • In the PUT request endpoint, I was searching for ways to optimally update the todo and discovered this
    todos[indexOfReq] = { ...todos[indexOfReq], ...req.body }; 
    

    Here the spread operator(...) merges the existing todo with the data from the request body.

    • As part of the assignment, I also had to implement a global middleware which would count the average time it takes to reply to a request.
    app.use((req,res,next)=>{
    const start = Date.now();
    
    res.on("finish" , ()=>{
      requestCount++;
      const reqDuration = Date.now() - start;
      totalTime +=reqDuration
    })
    console.log((totalTime/requestCount).toFixed(2));
    next();
     })```
    
    

🔚 Wrapping Up Week 1

This week was intense but super rewarding!
It’s amazing how quickly theory turns into something tangible, by the end of the week, I had a working file server and a todo app up and running.

Excited to see what Week 2 has in store as I continue building my full-stack skills. Onward and upward from here!

Top comments (0)