SimonTopp / ds-pipelines-targets-2

https://lab.github.com/USGS-R/usgs-targets-tips-and-tricks
0 stars 0 forks source link

myData.save is not a function #4

Closed adiswordfish closed 3 years ago

adiswordfish commented 3 years ago

I am making a project which is a form and you fill the data and when you press submit if the data is stored it should show "This item has been saved to the database" and if did not store it, it should show "The item was not saved to the database". I am working on vscode. Here is my code:

index.pug

meta(charset="UTF-8") meta(http-equiv="X-UA-Compatible", content="IE=edge") meta(name="viewport", content="width=device-width,initial-scale=1") //- link(rel="stylesheet", href="C:\Users\adity\OneDrive\Documents\Coding\web_dev\js_projects\Form\style.css") //- script(src="C:\Users\adity\OneDrive\Documents\Coding\web_dev\js_projects\Form\app.js") style include style.css include app.js title Document ul li a(href="https://www.homecentre.in/in/en/") Home li a(href="https://www.hindustantimes.com/india-news") News li a(href="https://play.google.com/store/apps/details?id=com.google.android.contacts&hl=en_IN&gl=US") Contact li a(href="https://www.ienglishstatus.com/cool-whatsapp-status/") About br form(action="/form", method="post", class="myForm") input(type="text", placeholder="Enter your name", name="name", id="name") br br input(type="number", placeholder="Enter your age", name="age", id="age") br br input(type="password", placeholder="Enter your password", name="password", id="password") br br button(type="submit") submit

app.js

const express = require("express") const path = require("path") const app = express() const port = 1470 const bodyparser = require("body-parser") const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true, useUnifiedTopology: true});

app.use('/static', express.static('static')) // For serving static files

// Schema Mongoose var formSchema = new mongoose.Schema({ name: String, age: String, password: String

});

// PUG SPECIFIC STUFF app.set('view engine', 'pug') // Set the template engine as pug app.set('views', path.join(__dirname, 'views')) // Set the views directory

// ENDPOINTS app.get('/', (req, res)=>{ const params = {} res.status(200).render('C:\Users\adity\OneDrive\Documents\Coding\web_dev\js_projects\Form\index.pug', params); })

app.post('/form', (req, res)=>{ var myData = "new Contact(req.body);" myData.save().then(()=>{ res.send("This item has been saved to the database") }).catch(()=>{ res.status(400).send("item was not saved to the databse") })})

app.listen(port, ()=>{ console.log("Server is running on localhost 1470"); })

style.css

body{ text-align: center; background: tomato; }

li{ list-style: none; display: inline-block; font-weight:bold; / background-color: white; color: red; / }

a{ color:wheat; list-style: none; text-decoration: none; padding-left: 130px; padding-right: 100px;

}

ul{ background-color: black; }

The error is: TypeError: myData.save is not a function

All help is appreciated 🙏

lindsayplatt commented 3 years ago

Hello @adiswordfish! It looks like your issue is related to a different repository. I don't know much about what you are doing, but I see you mention vscode, so I would suggest heading over to the vscode repo: https://github.com/microsoft/vscode and submitting your issue there. Best of luck!