npm install mongoose --save
const mongoose = require('mongoose');
const mongoose = require('mongoose');const mongoURL="mongodb://localhost:27017/react"const connectToMongoDB=()=>{
mongoose.connect(mongoURL).then(()=>console.log('success')).catch(err => console.log(err));
}
module.exports=connectToMongoDB;
const connectToMongoDB =require('./db') connectToMongoDB()
const mongoose = require("mongoose");
const { Schema } =mongoose;
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
date: {
type: Date,
default: Date.now,
},
});
const Kitten = mongoose.model('Kitten', kittySchema);
const silence = new Kitten({ name: 'Silence' });
console.log(silence.name);