JS/Node.js7 [Node.js] : ํ์๊ฐ์ ์ ์ด๋ฉ์ผ ์ธ์ฆ ๋ก์ง ๊ตฌํํ๊ธฐ. ๊ตฌํํ๊ณ ์ถ์ ๊ธฐ๋ฅ ํ์๊ฐ์ ์์ ์์ฑํ ์ด๋ฉ์ผ์ ํตํด์ ํ์๊ฐ์ ์ธ์ฆ์ ๊ฑฐ์น๋ ๋ก์ง์ ๊ตฌํํ๊ณ ์ถ์. (ํ์ฌ Nodemailer๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌํ์ค์ ์์ผ๋ฉฐ, ์ฌ๋ฌ ์ค๋ฅ๋ค์ ๋ง๋์, ์ฝ๋ ํ๋ํ๋์ ์ญํ ์ ํ์ ์ค์ ์๋ค.) ์ฐ์ ์ง๊ธ๊น์ง์ ๊ณผ์ ์ ๋์ดํ๊ณ ๋ง๋ ์ค๋ฅ๋ค์ ์ ๋ฆฌํ๊ณ ์ ํ๋ค. ์ฌ์ฉํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ // package.json "dependencies": { "cookie-parser": "^1.4.6", "dotenv": "^16.3.1", "express": "^4.18.2", "jsonwebtoken": "^9.0.1", "mysql2": "^3.5.1", "nodemailer": "^6.9.3", "sequelize": "^6.32.1" }, "devDependencies": { "nodem.. 2023. 7. 19. [Node.js] : ํ๋ก์ ํธ ๊ธฐ๋ณธ ์ธํ package.json ํ์ผ ์์ฑ npm init -y ์ฌ์ฉํ๊ณ ์ ํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น npm i sequelize ์ค์น npm i sequelize // ํฐ๋ฏธ๋์์ ๋ช ๋ น์ด๋ฅผ ํตํด sequelize๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ๋ช ๋ น์ด npm i sequelize-cli config ํด๋ ์์ฑ // sequelize๋ฅผ ์ฌ์ฉํ ์ ์๋ ๊ตฌ์กฐ๋ฅผ ์์ฑ npx sequelize init // config ํด๋๊ฐ ์์ฑ๋๋ค. ์ด์ DB์ฐ๊ฒฐํ๊ณ ์์ ์์. #์๋ฒ์ธํ #sequelize #๊ธฐ๋ณธ์ธํ 2023. 7. 17. [package.json] : ์ค์นํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ญ์ ๋ฐฉ๋ฒ ํ์ฌ ์ค์น๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์์ mysql์ ์ญ์ ํ๊ณ ์ถ๋ค. npm uninstall ํด๋น ๋ช ๋ น์ด๋ก ์ค์นํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ญ์ ํ ์ ์๋๊ฑธ ์๊ฒ๋์๋ค. #๋ผ์ด๋ธ๋ฌ๋ฆฌ_์ญ์ #uninstall 2023. 7. 17. [Sequelize] : Posts.findAll(...).sort is not a function ์ค๋ฅ ํด๊ฒฐ ๊ธฐ์กด mongoDB๋ฅผ ์ฌ์ฉํ๋ ๋ถ๋ถ์์ Sequelize๋ฅผ ์ ์ฉํด SQL๋ก ๋ณํํ๋ ๊ณผ์ ์์ ์ฝ๋์์ ์๋ฌ๊ฐ ๋ฐ๊ฒฌ๋์๋ค. ์ค๋ฅ ๋ฐ๊ฒฌ ๋ถ๋ถ // ../routes/posts.js router.get('/posts', async (req, res) => { try { // ์์ฑ๋ ์ง ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌํ๊ณ , posts์ ํ ๋น. const posts = await Posts.findAll({}).sort('-createdAt').exec(); (...) } }) ๊ธฐ์กด์ ์ ์ฒด ๊ฒ์๊ธ์ ์กฐํํ๊ณ ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌ์ํค๋ ๋ถ๋ถ์์ ์ค๋ฅ ๋ฐ์ ์ค๋ฅ ๋ด์ฉ Posts.findAll(...).sort is not a function ์ ์ฝ๋๋ฅผ ํจ์๋ก ์์๋ฃ์ง ๋ชปํ๋ค์ ์ด์ sort ๋ฉ์๋์ exec ๋ฉ์๋๋ mongoDB.. 2023. 7. 14. [Node.js] : Sequelize ์ค๋ฅ TypeError: Users.findOne is not a function ๋ ์ด์์ ์ด ์ค๋ฅ์ ์๊ฐ์ ์์ง ์๊ธฐ ์ํด์ ์ ๋ฆฌํ๋ค. ์ด ์ค๋ฅ๋ฅผ ํด๊ฒฐํ๋ ค๊ณ ์ง๊ธ์ง๊ธํ๊ฒ ํด๋งธ์.... ๋ฑ ์ด 5๊ฐ์ง // 1๋ฒ : ์ ์์ฝ๋ const { Users } = require('../models'); // 2๋ฒ : TypeError: Cannot read properties of undefined (reading 'findOne') const { Users } = require('../models/users'); // 3๋ฒ ~ 5๋ฒ : TypeError: Users.findOne is not a function const Users = require('../models'); const Users = require('../models/users'); const Users = require('.. 2023. 7. 13. [Node.js] : mongoose schema๋ฅผ ํตํ ๋ฐ์ดํฐ ์ ์ฅ ํ๊ณ ์ ํ๋ ์ผ ์คํค๋ง๋ฅผ ์ด์ฉํ DB์ ๊ทผ ๋ฐ ๋ฐ์ดํฐ ์์ฑ ์คํค๋ง๋ ? ์คํค๋ง๋ ๋ฐ์ดํฐ์ ๊ตฌ์กฐ์ ํ์ ์ ๊ฒฐ์ ํด์ฃผ๋ ์ญํ ์ ํ๋ ๊ฐ๋ ์ด๋ค. ๋ชฝ๊ณ ๋๋น ์ฐ๊ฒฐ mongoose ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น npm i mongoose ์ค์นํ mongoose๋ฅผ ํตํด mongoDB์ ํฌํธ์ธ 27017๊ณผ ๋ด ์์ ํด๋ ์ฐ๊ฒฐํ๊ธฐ // /schemas/index.js const mongoose = require('mongoose'); const connect = () => { mongoose .connect('mongodb://localhost:27017/3-personal-assignment-create-backend-server') .catch((err) => console.log(err)); }; mongoose.connection... 2023. 6. 16. ์ด์ 1 2 ๋ค์