Since the MERN stack is very popular, there are some great tutorials out there. I can highly recommend Creating a REST API with Node.js and An Easy Way to Get Started with the MERN Stack by alligator.io , for instance.
What is a RESTful API?
REST stands for REpresentational State Transfer. It’s an architectural style that defines a set of constraints and properties based on HTTP. It was first presented by Roy Fielding in 2000 in his famous dissertation.
REST has six architectural constraints, which you can read more about here.
I have Node installed, so I created a directory
cd into it, and ran
npm init to create a
package.json file. Next, I installed Express with the command
npm install --save express.
Next, I created a simple
server.js file, in order to set up my Node server.
After that, I added an
app.js file and hooked it up with the bare-bones server.
After starting the server with node server.js, I opened up
localhost:3000 in the browser, just to check that everything works:
Now that we have a very basic server running, it’s time to add more routes, a database, and more. That, however, I’m going to save for my next blog post.