0
I’m trying to make a connection with mblab but the connection method is deprecated. Version of the method is 4.9.7. What I need is 4.13.7.
Structure:
server.js
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const hbs = require('hbs');
const expressHbs = require('express-handlebars');
const config = require('./config/secret');
const app = express();
mongoose.connect(config.database, function(err) {
if (err) console.log(err);
console.log("connected to the database");
});
app.engine('.hbs', expressHbs({ defaultLayout: 'layout', extname: '.hbs' }));
app.set('view engine', 'hbs');
app.use(express.static(__dirname + '/public'));
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const mainRoutes = require('./routes/main');
app.use(mainRoutes);
app.listen(3030, (err) => {
if (err) console.log(err);
console.log(`Running on port ${3030}`);
});
secret js.
module.exports = {
database: ''
}
main.js
const router = require('express').Router();
const User = require('../models/user');
router.get('/', (req, res, next) => {
res.render('main/landing');
});
router.get('/create-new-user', (req, res, next) => {
var user = new User();
user.email = "[email protected]"
user.name = "Jack";
user.password = "123456";
user.save(function(err) {
if (err) return next(err);
res.json("Successfully created");
});
});
module.exports = router;
user js.
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const UserSchema = new Schema({
email: { type: String, unique: true, lowercase: true },
name: String,
password: String,
photo: String,
tweets: [{
tweet: { type: Schema.Types.ObjectId, ref: 'Tweet' }
}]
});
module.exports = mongoose.model('User', UserSchema);
dependencias": {
“body-parser”: “^1.18.2”,
“express”: “^4.16.2”,
“express-handlebars”: “^3.0.0”,
“hbs”: “^4.0.1”,
“mongoose”: “^4.13.7”,
“morgan”: “^1.9.0”
}
Edith question and place the code instead of images!
– NoobSaibot