Managing Data Flow: Storing and Retrieving Information with Express.js and Node.js | CodeSignal Learn
Skip to main content
Learning to Store and Retrieve Data: Data Storage

Think of our server as a library that houses key app data. In this lesson, we will learn how to store this data in our server. We'll use JavaScript to create JSON objects, which will store our data in an easily accessible manner. Imagine that we're building a blog app, and we are storing a list of blog posts.

Here, our data object stores an array of blog post objects. Each post has an id, title, and content.

Learning to Store and Retrieve Data: Data Retrieval

Just as a library retrieves books for you, our server fetches data when needed. We use routes in Express.js to handle these requests.

This line instructs the server to respond to a GET request at /api/posts with the posts data in our data object.

Learning to Store and Retrieve Data: Modifying Data

Communicating data between the client and server is a two-way street. Not only do we need to send data from the server to the client, but we often need to update our server-side data based on information received from the client. Therefore, we'll see how to modify data on the server based on client-side input.

Specifically, we'll use the HTTP POST method, which is designed to send data in a request to a server.

Important: Before handling POST requests with JSON data, we need to add middleware to parse JSON request bodies:

Imagine a user who wants to add a new blog post. They'd fill in the details on our client-side app, which would then package this data and send it over to our server using Axios. Let's see what the client-side code for this might look like:

In this code, we're sending a new post to our server using axios.post(). The new post data is included in the request. Notice we don't include an id in the client - the server will generate that. Once the server receives the POST request, it sends back a response with the newly created post, including its id.

Let's see how we can set up our server to receive this POST request and add the new post to our data:

In this code, our server is set up to receive a POST request at the endpoint. The contains the data our client sent - the new post. We generate a new for the post, add it to our array, and send the complete post (including the new ) back in the response.

Lesson Summary

Congratulations! You have successfully tackled data handling with Express.js. You now understand how to set up your server to store data, how to fetch and modify this data upon a client request, and how to use Axios to handle GET and POST requests. Now, undertake the exercises to test your new skills. Keep practicing, and continue your journey toward becoming a seasoned web developer!

Previous Lesson
Previous
Next Lesson: Navigating the Cosmos: Implementing Routes and Middlewares in Express.js
Next Lesson: Navigating the Cosmos: Implementing Routes and Middlewares in Express.js
Next
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal
/api/posts
req.body
id
posts
id

By running the above code, you can now add new posts to your server data through your client app! This prepares you for more realistic handling of server data in your future web development endeavors.

Home
Paths
Home
Company
AboutCareersLeadershipTalent ScienceNewsroom
Collections
Generative AIBusiness & LeadershipInterview PrepAI & Machine LearningLearn to CodeData Science & Engineering
Platform
Platform OverviewSkills AssessmentsLive Tech InterviewsAI InterviewerAI Role-PlayAI Tutoring with CosmoCertified Assessments
Roles
Talent AcquisitionEngineering LeadersSales LeadersCS & Support LeadersIO PsychologistsIndividuals
Resources
Resource LibraryBlogCustomer StoriesInterview PrepAPI Docs
Support
Knowledge Base
Home
Copyright © 2025 CodeSignal
PrivacyTermsSecurity & Compliance