Full Stack: Flutter & NodeJS implementing authentication-Part 2, NodeJs Register User API

Kafka
3 min readJul 2, 2020

--

Welcome back to part 2. Here we are building the backend API With NodeJS. Basically, get the users email and password and save it into MongoDB. All right let's get started.

If you don't like to read and rather watch the video instead.

This is the entire backend code in one file. Some error handling could be added, But overall so far so good.

So setting up the basic express server is the easiest part. I literally started from the hell world example.

Import express and Then we change the port number to port 5000.

Next up we need to set up a connection to mongo DB.

If you're wondering where that mongoDB url is coming from. It's coming from Mlab. Basically a free hosting service for your database.

Once we have a connection to the database we can build the API route.

So this is the entire code in the signup route. But we can break it down.

So the first thing is we're trying to get the email and password for the user from a post method. And we can do this with a Built in express tool called express.Json( )

Next we have a model to how we want to store data into mongo DB. The email is a string and the password is also a string.

Can we set up how we want to save the data And what data is going to be saved.

And finally we save the data with the save method. And we sending fake token confirming the data was saved.

Source Code

That’s it guys. This was the backend NodeJS tutorial for flutter. I hope you guys got something out of this article. If this article helped you go ahead and smash that clap button. Cheers 🍺

All Parts: Full Stack PlayList

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Kafka
Kafka

Written by Kafka

“Genius” is 1% inspiration and 99% perspiration. Accordingly, a ‘genius’ is often merely a talented person who has done all of his homework — T.E.

No responses yet

Write a response