-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Landing page #11
base: master
Are you sure you want to change the base?
Landing page #11
Conversation
const mongoose = require('mongoose') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'm setting the db URL here as a constant but i was planning to make it as environment variable later
- I'm using express-async-errors package to handle errors like this one here
- You used callback function to handle the connection result but the error is already handled by the error middleware and everything is logged using Winston package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you are saying, but for some reason, this is not connecting to the db. The winston logging is great, and very handy!! I'll see if i can resolve this problem... any suggestions to incorporate winston? (the change i made to this file connected to mongodb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly I don't get you, can you elaborate for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously the way the file was set up there was no connection being made to the local mongoDB. The way i had rewritten the file connected to the local database so data was being added and could be retrieved from the mongoDB file.
I have now changed the code back to how you had it, removing the export function and adding "useCreateIndex: true".
The connection is now working to mongodb and a message is being added to the logfile.
@@ -0,0 +1,30 @@ | |||
const express = require('express') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I have exactly the same code but in
routes.js
why you changed the file name ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using index.js inside a directory means that you only need to require the directory name when importing the module.
eg: const app = require('../startup')
instead of
const app = require("../startup/routes")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured this out and found it quite useful thank you
the app crashes with me giving
|
resolved by fixing |
Hi, localhost:8080/api/courses/seed = will seed the database with courses localhost:8080/api/courses - will render with the courses listed Do you want to ba able to see the courses only after you have logged in? Or do you want to see them on the home page and only be able to add new courses or edit courses once you are logged in?? |
@@ -19,11 +20,16 @@ const schema = new mongoose.Schema({ | |||
}, | |||
}, | |||
}) | |||
module.exports = mongoose.model('Course', schema) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the point why you write the same code I've written before in a different style ?
function validateCourse(course) { | ||
const schema = Joi.object({ | ||
name: Joi.string().min(3).required(), | ||
tags: Joi.array(), | ||
}) | ||
return schema.validate(course) | ||
} | ||
|
||
exports.validate = validateCourse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a kind of easier way or just a typo ?
|
HI this isn't finished (obviously) just thought i'd push this up so you can see what i've been doing, i have refactored some of the file names. This is to take advantage of how index.js works in directories, also so you don't have lines and lines of imports/requires from a directory. I also separated concerns out of the app/index start file for the server, so all it does is set the local host.
I'm using Bootstrap 4 for css if thats alright, happy to use something else if you have a preferred CSS framework.