how to install mongoose
$ npm install mongoose
how to install mongoose
$ npm install mongoose
mongoose npm
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database', {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
.then(()=> console.log('connect'))
.catch((error) => console.error(error));
mongoose
import express from 'express';
or
const exporess = require('express');
import mongoose from 'mongoose';
or
const mongoose = require('mongoose');
const app = express();
mongoose.connect('mongodb://localhost:27017/mongo-tree' , {
useNewUrlParser: true,
useUnifiedTopology: true
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('connected db')
});
app.use('/', (req, res) => {
res.send('hello');
}
);
const port = process.env.PORT || 5000
app.listen(port, () => {
console.log('running');
})
//for es6 >npm i @babel/core @babel/node @babel/preset-env --save-dev
//create .babelrc file and put this
{
"presets": [
"@babel/preset-env"
]
}
//and package.json
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "nodemon --exec babel-node server"
},
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us