0

How do I collect HTML form data when hosting and store it on my MongoDB database?

I am trying to setup a small application to collect form data from users and store it on MongoDB database. I was able to do this on my local server by setting the HTML action attribute to point to my localhost route used for setting up the Express post method which is http://localhost:4000/login. I also connected to the MongoDB database using mongodb://localhost:27017/db and everything works fine. My question is how do I make this work on a hosting platform like Netlify which I am currently using? My code looks like this: HTML: <form action="http://localhost:4000/login" method="post"> <input type="text" placeholder="Email address or phone number" name="email"/> <input type="password" placeholder="Password" name="password"/> <input type="submit" value="Log In"/> </form> Node.js: mongoose.connect('mongodb://localhost:27017/db') app.post('/login', async (req, res) => { const data = res.body response = await Login.create(data) } )

11th Feb 2022, 7:44 PM
Logos
Logos - avatar
1 Respuesta
+ 3
Use mongodb altas... It's cloud based database... learn more about here: https://docs.atlas.mongodb.com/
11th Feb 2022, 8:02 PM
Rupali Haldiya
Rupali Haldiya - avatar