Flare-k

Connect MongoDB and Setting dotenv

import { videos } from "../db";
import routes from "../routes";
export const home = (req, res) => {
......@@ -24,7 +23,9 @@ export const postUpload = (req, res) => {
res.redirect(routes.videoDetail(324393));
};
export const videoDetail = (req, res) => res.render("videoDetail", { pageTitle: "Video Detail" });
export const editVideo = (req, res) => res.render("editVideo", { pageTitle: "Edit Video" });
export const deleteVideo = (req, res) => res.render("deleteVideo", { pageTitle: "Delete Video" });
\ No newline at end of file
export const videoDetail = (req, res) =>
res.render("videoDetail", { pageTitle: "Video Detail" });
export const editVideo = (req, res) =>
res.render("editVideo", { pageTitle: "Edit Video" });
export const deleteVideo = (req, res) =>
res.render("deleteVideo", { pageTitle: "Delete Video" });
\ No newline at end of file
......
export const videos = [{
id: 324393,
title: "Video awesome",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
{
id: 1212121,
title: "Video super",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
{
id: 55555,
title: "Video nice",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
{
id: 11111,
title: "Video perfect",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
];
\ No newline at end of file
import mongoose from "mongoose";
import dotenv from "dotenv";
dotenv.config();
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useFindAndModify: false,
});
const db = mongoose.connection;
const handleOpen = () => {
console.log("✅ Connected to DB");
};
const handleError = (error) =>
console.log(`🔴 Error on DB Connection: ${error}`);
db.once("open", handleOpen); //connection을 열고 성공여부를 확인할 수 있는 function을 만들 것이다.
db.on("error", handleError);
\ No newline at end of file
......
import app from "./app"; // app.js에서 export default app했기 때문에 불러올 수 있다.
import "./db";
import dotenv from "dotenv";
dotenv.config();
const PORT = 80;
const PORT = process.env.PORT || 80;
const handleListening = () => {
console.log(`-> Listening on: http://localhost:${PORT}`);
console.log(` Listening on: http://localhost:${PORT}`);
//call-back함수.
//PORT를 listen하기 시작할 때 함수를 호출해준다.
}
};
app.listen(PORT, handleListening);
\ No newline at end of file
......