What is the role of Nodejs and Express in a MERN stack web application when GraphQL is also used

0 votes
I realise this is a really basic issue, but I'm having trouble grasping a couple concepts related to the MERN stack and GraphQL. On github, there is a project that uses MongoDB, Express, React, and Nodejs, as well as GraphQL, to create a web app.

I get that MongoDB is used for data storage and React is used for the front end, but I'm not sure why Express and Nodejs are utilised when a GraphQL API is developed that POSTs and GETs data directly to/from the MongoDB database? What is the relationship and role of nodejs, express, and graphql?

This inquiry may not make sense to you because I lack basic knowledge of web app development concepts and an understanding of web dev stacks like MERN.
May 27, 2022 in Node-js by Vaani
• 7,070 points
2,592 views

1 answer to this question.

0 votes
Node.js is a JavaScript runtime environment, which means it's responsible for running all of your server-side code. Express is a Node.js framework with basic functionalities for constructing web applications. While Node.js can already listen on a port for requests, Express simplifies the process of setting up a web server by removing boilerplate and providing a simpler API for constructing endpoints.

A query language is GraphQL. The JavaScript implementation of GraphQL is GraphQL.js. Neither is capable of generating a web server or an endpoint. GraphQL does not listen to requests forwarded to a certain port. This is what Express is for: when used with another library like apollo-server-express or express-graphql, it puts up our endpoint, waits for incoming requests, parses them, and passes them to GraphQL to execute. The execution result is then sent back to the client who submitted the request.

GraphQL.js, on the other hand, is unable to connect to a database directly. In response to a request, GraphQL simply executes the code you give. The actual database contact is usually done through a driver (such as mongodb) or an ORM (like mongoose).

So a client (like your React app) sends a request to your Express app, which parses it and sends it to GraphQL, which runs your query and, in the process, invokes some code that retrieves data from your database. This information is structured and returned to the client in an appropriate response.
answered May 27, 2022 by Neha
• 9,020 points

Related Questions In Node-js

0 votes
1 answer

How to get the _id of inserted document in Mongo database in NodeJS?

Hello @kartik, A shorter way than using second ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,880 points
13,728 views
0 votes
1 answer

How to split and modify a string in NodeJS?

Hello @kartik, Use split and map function: var str = "123, 124, 234,252"; var ...READ MORE

answered Oct 16, 2020 in Node-js by Niroj
• 82,880 points
1,157 views
0 votes
1 answer

How do I manage MongoDB connections in a Node.js web application?

When the Node.js application starts, create a ...READ MORE

answered Jun 10, 2022 in Node-js by Neha
• 9,020 points
1,936 views
0 votes
1 answer

NodeJS / Express: what is "app.use"?

The app object is instantiated on creation ...READ MORE

answered Jun 17, 2022 in Node-js by Neha
• 9,020 points
988 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,901 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,428 views
0 votes
1 answer

Unable to start express server on AWS instance

It's not your code — you can't connect ...READ MORE

answered Oct 1, 2018 in AWS by Priyaj
• 58,100 points
3,072 views
0 votes
1 answer

How to schedule a google meet and get the meet link in NodeJs?

To create a Google Meet, you'll need ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
3,848 views
0 votes
1 answer

How to host MEAN stack application with Angular and nodejs on windows IIS

It's fine that you're using Angular. Be ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
1,306 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP