Question: CS 602 Server Side development hw3 please explain and comment the following node.js code module.exports = { // host: 'localhost', // port: '27017', host: 'ds115768.mlab.com',

CS 602 Server Side development hw3 please explain and comment the following node.js code

module.exports = { // host: 'localhost', // port: '27017', host: 'ds115768.mlab.com', port: '15768', username: 'cs602_user', password: 'cs602_secret', database: 'cs602db' }

part 2

var mongoose = require('mongoose'); var Schema = mongoose.Schema;

var employeeSchema = new Schema({ firstName: String, lastName: String });

module.exports = { getModel: function getModel(connection) { return connection.model("EmployeeModel_sk", employeeSchema); } }

part 3

var mongoose = require('mongoose');

const credentials = require("./credentials.js");

const dbUrl = 'mongodb://' + credentials.username + ':' + credentials.password + '@' + credentials.host + ':' + credentials.port + '/' + credentials.database;

const connection = mongoose.createConnection(dbUrl);

var EmployeeDb = require('./employeeDb.js'); var Employee = EmployeeDb.getModel(connection);

connection.on("open", function(){ // create and save document objects var employee;

employee = new Employee({ firstName:'John',lastName:'Smith' }); employee.save();

employee = new Employee({ firstName:'Jane',lastName:'Smith' }); employee.save();

employee = new Employee({ firstName:'John',lastName:'Doe' }); employee.save(function(err) { connection.close(); if (err) throw err; console.log("Success!"); }); });

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!