Submitted August 01, 2020 at 09:18PM by Iloveyoufridah
Saturday, 1 August 2020
How can i connect frontend to node so as to transfer data to mongodb?
Hello guys? i would like some pointers on how to connect my frontend to the node backend. I have two documents, the first is this server.js file, Using the code below I can directly post data to the database, what i would like to learn is how I can pass the data in the frontend code and it directly goes to the database.const express = require('express');const mongoose = require('mongoose');mongoose.connect('mongodb+srv://jeremy:12345@trial1-vdcgr.mongodb.net/first-test?retryWrites=true&w=majority',{useNewUrlParser: true, useUnifiedTopology: true})const Personnew = mongoose.model('Person', {fname: String ,lname: String,email: String,password:String});const usernew = new Personnew({ fname: 'nameone',lname:'Brian',email:'haha@gmail.com',password:'123456' });usernew.save().then(() => console.log('Connected to the server'));const app = express();app.use(express.static('frontend'))app.use(function (req, res, next) {res.status(404).send("Cannot find your requested resource!!")})app.listen(3000,()=>{console.log('server is connected on port 3000')});I have this register.html which I would like to pass the data from, here it is:
Document
If anyone could me some pointers, or guide me to a resource that would help me pass this data from frontendThanks
Submitted August 01, 2020 at 09:18PM by Iloveyoufridah
Submitted August 01, 2020 at 09:18PM by Iloveyoufridah
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment