๐Ÿ˜Ž ๊ณต๋ถ€ํ•˜๋Š” ์ง•์ง•์•ŒํŒŒ์นด๋Š” ์ฒ˜์Œ์ด์ง€?

[Login & Register authentication with Node js] (4) MongoDB ์—ฐ๊ฒฐํ•˜๊ธฐ & ๋Œ€์‰ฌ๋ณด๋“œ ํŽ˜์ด์ง€ ๊ตฌ์ถ•ํ•˜๊ธฐ ๋ณธ๋ฌธ

๐Ÿ‘ฉ‍๐Ÿ’ป ๋ฐฑ์—”๋“œ(Back-End)/Node js

[Login & Register authentication with Node js] (4) MongoDB ์—ฐ๊ฒฐํ•˜๊ธฐ & ๋Œ€์‰ฌ๋ณด๋“œ ํŽ˜์ด์ง€ ๊ตฌ์ถ•ํ•˜๊ธฐ

์ง•์ง•์•ŒํŒŒ์นด 2023. 3. 15. 01:23
728x90
๋ฐ˜์‘ํ˜•

<๋ณธ ๋ธ”๋กœ๊ทธ๋Š” Traversy Media ์˜ ์œ ํŠœ๋ธŒ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค :-)>

=> Node.js With Passport Authentication | Full Project

=> authentication app with login, register and access control using Node.js, Express, Passport, Mongoose

 

 

๐Ÿฅ• Dashboard ํŽ˜์ด์ง€

๐Ÿง views/dashboard.ejs

<h1 class="mt-4">Dashboard</h1>
<p class="lead mb-3">Welcome <%= user.name %></p>
<a href="/users/logout" class="btn btn-secondary">Logout</a>

 

 

๐Ÿฅ• MongoDB ์—ฐ๊ฒฐํ•˜๊ธฐ

๐Ÿง app.js

const express = require("express");
const expressLayouts = require("express-ejs-layouts");
const mongoose = require("mongoose");
require("dotenv").config();

const app = express();

// DB config
const db = process.env.MONGODB_URI;

// connect to Mongo
mongoose.connect(process.env.MONGODB_URI,{ 
  useNewUrlParser: true,    // useNewUrlParser : ์—๋Ÿฌ ๋ฐฉ์ง€
  useUnifiedTopology: true
})
  .then(()=> console.log("๐Ÿ’šMongoDB Connected..."))
  .catch(err => console.log(err));


// ejs ๋ฏธ๋“ค์›จ์–ด
app.use(expressLayouts);
// express ์˜ view ์—”์ง„์„ ejs ๋กœ ์„ธํŒ…
app.set("view engine", "ejs");
// img
app.use(express.static('public'));

// Routes
app.use("/", require("./routes/index"));
app.use("/users", require("./routes/user"));

const PORT = process.env.PORT || 8000;

app.listen(PORT, console.log(`๐Ÿš€Server started on port http://localhost:${PORT}`));

728x90
๋ฐ˜์‘ํ˜•
Comments