
49,500원
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
ES6 Sequelize.sync error
안녕하세요 현재 cjs 가 아닌 es6 로 nodejs 코드를 작성하고 있습니다. 9-2 강의 진행 중 강사님 깃헙 리포지토리 9-2 폴더 중 app.js 20번 줄에서 sequelize.sync is not a function 이라는 오류가 나옵니다. 구글 검색을 해본 결과 일부 블로그에서 es6 에서는 해당 함수를 사용이 불가하다는 글을 보았습니다. 그리고 models/index.js 파일에서 fs.readdirSync(__dirname) .filter(file=>{ return file.indexOf('.') !== basename && file.slice(-3) === '.js'; }) .forEach((file) =>{ import(path.join(__dirname,file)) .then((obj) => {console.log(obj.name); obj(sequelize, Sequelize.DataTypes); db[obj.name] = obj; obj.initiate(sequelize);}) .catch(err => console.log(err)); //const model = require(path.join(__dirname, file)); //console.log(file,model.name); //db[model.name] = model; //model.initiate(sequelize); });주석 처리한 부분은 cjs 스타일이고 변경한 부분은 동적 import 를 사용해서 구현해보았습니다. 구글 검색 후 obj(sequelize, Sequelize.DataTypes) 구문을 삽입하면 해당 오류가 해결이된다고 했으나 해결이 되지 않습니다. 오류설명이 구구절절 길었으나 제 질문을 정리하자면해당 함수(sequelize.sync)가 es6에서는 사용이 안되나요?사용이 안되다면 전면 cjs 로 바꿔 코드 작성을 해야하나요?입니다. es6 코드 작성을 연습하고자 코드를 변경해가며 진행중인데 난관을 겪었습니다. 질문 유의사항을 잘지켜야지 하며 적었는데 가독성이 있을지는 모르겠습니다. 감사합니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
슬랙방에 들어가지지 않습니다
선생님 안녕하세요슬랙방 링크를 클릭하니 이런 페이지가 뜹니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
버퍼와 스트림 강의 질문
강의내용이 영상이 아닌, 파일로 되어 있는 것 같은데,다운로드 링크가 보이지 않는 것 같습니다.어디서 다운로드 할 수 있을까요? 아니면 혹시 이전 영상이 3-12 이고 이 강의 다음영상이 3-14로 되어 있던데, 영상이 빠진 거 일까요?
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
/usr/local/etc/mongod.conf 파일이 없음
맥에서 vim /usr/local/etc/mongod.conf 를 입력했는데 기존 파일이 없어서 새로 작성되고, :wq!로도 저장이 안됩니다.그리고 애초에 /usr/local 밑에 etc 폴더가 없습니다. 어떻게 해결해야 하나요?위의 과정 없이 mongo admin -u를 진행하니 에러가 뜹니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
passport.authenticate('local/kakao') 관련 질문
안녕하세요routes/auth.js에서 passport.authenticate('local' / 'kakao')로 로그인전략을 실행할 때auth.js에서는 local(), kakao()가 있는 passport/index.js를 require 한 적이 없는데도 실행되는 걸 보고 질문드립니다.passport 모듈 내에 passport폴더를 자동으로 인식하는 기능이 있는건가요?
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
몽구스 버전 관련 문의
안녕하세요 선생님 오늘도 질문드립니다.npm i mongoose 하면 자동으로 설치되는 7.0.0버전에서는 예제코드 실행하면 다음과 같은 오류가 발생합니다. throw new MongooseError('Mongoose.prototype.connect() no longer accepts a callback'); ^MongooseError: Mongoose.prototype.connect() no longer accepts a callback at Mongoose.connect (C:\Users\newsu\Desktop\NodeJS\ch8\learn-mongoose\node_modules\mongoose\lib\index.js:400:11) at connect (C:\Users\newsu\Desktop\NodeJS\ch8\learn-mongoose\schemas\index.js:7:12) at Object.<anonymous> (C:\Users\newsu\Desktop\NodeJS\ch8\learn-mongoose\app.js:18:1) at Module._compile (node:internal/modules/cjs/loader:1246:14) at Module._extensions..js (node:internal/modules/cjs/loader:1300:10) at Module.load (node:internal/modules/cjs/loader:1103:32) at Module._load (node:internal/modules/cjs/loader:942:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) at node:internal/main/run_main_module:23:47 6버전대로 낮춰서 실행해보니 작동하긴 하는데, 7버전에서는 어떻게 해야하나요?
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
const config = require('../config/config')[env];를 es모듈로 불러오는 방법
안녕하세요 자꾸 글 작성했다 지웠다 해서 죄송합니다.직접 검색해보고 해결해보려했는데 안되어서 다시 남깁니다. 7.6장 model/index.js 파일중에서const config = require('../config/config')[env];수업에 나왔던 이 코드와 동일하게 동작하게끔 es모듈 방식으로 import하는 코드를 작성하려 합니다import cfg from '../config/config.json' assert { type : 'json' } const config = cfg[env]; 이렇게 작성해 보았는데(node:10404) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time(Use node --trace-warnings ... to show where the warning was created)이런 경고가 뜨고, 무시하고 app.js를 실행하면 서버가 실행되긴 하는데 책&예제코드에 나오는 메시지와는 다른 아래와 같은 메시지가 나옵니다.Executing (default): SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME = 'users' AND TABLE_SCHEMA = 'nodejs'Executing (default): SHOW INDEX FROM users FROM nodejsExecuting (default): SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME = 'comments' AND TABLE_SCHEMA = 'nodejs'Executing (default): SHOW INDEX FROM comments FROM nodejs 어떻게 해야 es모듈에서도 동일하게 동작하게끔 할 수 있는지 궁금합니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
수업 내용에 대해 질문드립니다.
안녕하세요http.createServer(async (req, res) => { try { if (req.method === 'GET') { if (req.url === '/') { const data = await fs.readFile(path.join(__dirname, 'restFront.html')); res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end(data); } else if (req.url === '/about') { const data = await fs.readFile(path.join(__dirname, 'about.html')); res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end(data); } else if (req.url === '/users') { res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' }); return res.end(JSON.stringify(users)); } // /도 /about도 /users도 아니면 try { const data = await fs.readFile(path.join(__dirname, req.url)); return res.end(data); } catch (err) { // 주소에 해당하는 라우트를 못 찾았다는 404 Not Found error 발생 } restFront.js , restFront.css 등을 받아오는 try 부분에서강의에는 const data = await fs.readFile(`.${req.url)`);로 수업하셨는데책과 깃헙예제에는 const data = await fs.readFile(path.join(__dirname, req.url)); 로 되어있어가지구요1. .${req.url}에서 백틱과 .은 꼭 쓰여야 하는건지랑2. 책의 예제코드에서 __dirname의 경로는 restServer.js가 있는 위치가 기준이 되는건지 질문드립니다. else if (req.method === 'POST') { if (req.url === '/user') { let body = ''; // 요청의 body를 stream 형식으로 받음 req.on('data', (data) => { body += data; }); // 요청의 body를 다 받은 후 실행됨 return req.on('end', () => { console.log('POST 본문(Body):', body); const { name } = JSON.parse(body); const id = Date.now(); users[id] = name; res.writeHead(201, { 'Content-Type': 'text/plain; charset=utf-8' }); res.end('등록 성공'); }); } } return req.on('end', () =>{}) 에서 'end'라는 이벤트가 어느 부분에서 발생해서 저기 들어가는건지도 궁금합니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
새로고침 한번에 클러스터 2개 종료
안녕하세요?setTimeout 대신 setImmediate를 적용해 요청이 발생하는 즉시 워커가 종료되게 해보았는데요, 이 경우엔 워커가 한번에 두개씩 종료됩니다.DevTool - network 창에 보이는 요청은 새로고침 1회당 GET 1회씩인데 왜 이러는지 궁금합니다! const cluster = require('cluster'); const http = require('http'); const numCPUs = require('os').cpus().length; if (cluster.isMaster) { console.log(`마스터 프로세스 아이디 : ${process.pid}`); // CPU 갯수만큼 워커를 생산 for (let i=0; i < numCPUs; i++ ){ cluster.fork(); } //워커가 종료되었을 때 cluster.on('exit', (worker, code, signal) => { console.log(`${worker.process.pid}번 워커가 종료되었습니다.`); console.log('code', code, `signal`, signal); }); } else { // 워커들이 포트에서 대기 http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8'}); res.write('<h1>Hello Node!'); res.end('<p>Hello Cluster!</p>'); setImmediate(()=> { process.exit(1); }); }).listen(8086); console.log(`${process.pid}번 워커 실행`); };
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
비동기 방식에서의 에러처리
안녕하세요! 어제 유투브에서도 질문드렸었는데 잘 이해가 가지 않아 다시 질문드립니다.184p server1-1.jsconst http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); res.write('<h1>Hello Node!</h1>'); res.end('<p>Hello Server!</p>'); }); server.listen(8080); server.on('listening', () => { console.log('8080번 포트에서 서버 대기 중입니다!'); }); server.on('error', (error) => { console.error(error); });어제 이 부분 에러처리를 try/catch로 하면 안되는건지 질문드렸었는데 server함수가 비동기로 진행되는거라 try/catch 적용하면 안된다고 답변받았었습니다. 186p server2.jsconst http = require('http'); const fs = require('fs').promises; http.createServer(async (req, res) => { try { const data = await fs.readFile('./server2.html'); res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); res.end(data); } catch (err) { console.error(err); res.writeHead(500, { 'Content-Type': 'text/plain; charset=utf-8' }); res.end(err.message); } }) .listen(8081, () => { console.log('8081번 포트에서 서버 대기 중입니다!'); });그런데 바로 뒤에서 async를 사용하여 비동기임이 확실한데도 try/catch로 에러처리를 하신 부분이 나와서 잘 이해가 안갑니다..뒷부분에서는 왜 try/catch를 적용해도 되는건지 궁금합니다!
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
클라이언트와 서버의 도메인이 다른 경우 쿠키 사용
클라이언트 도메인이 서버의 도메인과 다를 때 클라이언트에서 요청 받은 후 Set-Cookie로 응답 보낸 쿠키를 클라이언트 도메인에서도 접근이 가능한가요?
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
라우트 분리 및 템플릿 엔진 사용법 강의
안녕하세요. 이전 강의와 강의 교안과는 다르게, 개정3판 강의에서는 라우트분리 및 템플릿엔진 사용법과 관련된 강의가 빠져있더라고요.혹시 해당 강의들에 대해서 이번 개정판에서는 더 이상 학습하지 않아도 괜찮기 때문에 강의 내용에서 빠진 것 일까요?매번 좋은 강의로 감사합니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
AWS에서 MongoDB 설치
안녕하세요.15장을 듣다가 궁금해서 Node와 관련이 없는 질문을 드립니다.MySQL은 RDS를 쓴다고 하셨는데 MongoDB를 EC2에서 분리하여서 설치하는 서비스는 무엇인가요?감사합니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
mongodb Asio socket.set_option error
안녕하세요.개정 3판 Node.js 교과서 8-6 몽구스 실전 프로젝트에서 처음 프로젝트를 시작할 시, cd ch8/8.6/learn-mongoose 하여 폴더에 들어간 이후 npm start 에서 막혔습니다. terminal 상으로는 돌아가지만, localhost:3002로 접속했을때, 제대로 접속되지 않고 로딩창만 뜹니다. 저는 현재, intel MAC, Vertura 13.1 버전 쓰고 있으며, 노드 JS는 v18.12.1, mongodb는 6.0.4버전 쓰고있습니다.에러 메세지는 다음과 같습니다.몽고디비 연결 에러 MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at Connection.openUri (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/connection.js:825:32) at /Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:409:10 at promiseOrCallback (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/helpers/promiseOrCallback.js:11:14) at Mongoose._promiseOrCallback (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:1262:10) at Mongoose.connect (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:408:20) at connect (/Users/jisu/Downloads/nodejs-book-master/ch8/8.6/learn-mongoose/schemas/index.js:7:12) at Object.<anonymous> (/Users/jisu/Downloads/nodejs-book-master/ch8/8.6/learn-mongoose/app.js:18:1) at Module._compile (node:internal/modules/cjs/loader:1159:14) at Module._extensions..js (node:internal/modules/cjs/loader:1213:10) at Module.load (node:internal/modules/cjs/loader:1037:32) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined } MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 를 구글링하여 몇가지를 시도해봤는데,1번째, MONGO_URI=mongodb://localhost:27017/blog 를 MONGO_URI=mongodb://127.0.0.1:27017/blog 로 바꾸어 해결한 사례가 있어 ch8/8.6/learn-mongoose/schemas 폴더의 index.js에서mongoose.connect('mongodb://root:1234@localhost:27017/admin' 를 mongoose.connect('mongodb://root:1234@127.0.0.1:27017/admin', 로 바꾸었지만, → 해결되지 않았습니다.2번째, terminal에 mongod를 쳐서 error가 난 부분을 살펴보니,{"t":{"$date":"2023-02-07T00:55:42.260+09:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"} {"t":{"$date":"2023-02-07T00:55:42.263+09:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}} {"t":{"$date":"2023-02-07T00:55:42.280+09:00"},"s":"I", "c":"NETWORK", "id":4648602, "ctx":"thread1","msg":"Implicit TCP FastOpen in use."} {"t":{"$date":"2023-02-07T00:55:42.285+09:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I", "c":"CONTROL", "id":5945603, "ctx":"thread1","msg":"Multi threading initialized"} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":64400,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"iMac.local"}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.4","gitVersion":"44ff59461c1353638a71e710f385a566bcd2f547","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"22.2.0"}}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"F", "c":"ASSERT", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":1126}} {"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"F", "c":"ASSERT", "id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}이 부분에서, 에러인 부분인{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}이 부분이 에러일 것같다는 생각에, 구글링을 하던 중/tmp/mongodb-27017.sock 파일의 접근권한을 변경하거나 파일 삭제 후 서비스를 재시작하면 정상적으로 mongodb가 부팅된다.는 글을 보고, sudo rm -rf /tmp/mongodb-27017.sock로 sock 파일을 삭제해봤지만, 똑같은 결과였습니다.ls -l /tmp/mongodb-27017.sock로 확인했을때, 삭제된 것도 확인했습니다.3번째, terminal에 brew services list 로 mongodb상태를 확인해보려고 하였습니다.Name Status User File mongodb-community error 512 jisu ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist mysql none postgresql@14 none 로 나오는 것을 보아 mongodb가 제대로 작동되지 않고 있어서 에러가 발생하는 것으로 추측했습니다. brew services start mongodb-community의 결과로,Bootstrap failed: 5: Input/output error Try re-running the command as root for richer errors. Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/jisu/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist` exited with 5.가 나와서, 이를 해결하기 위해 mongodb-community를 완전히 지우고, brew cleanup까지 한 다음 다시 깔아봤지만 달라진 바는 없었습니다. 이전 강좌까지 mongodb에서 데이터베이스 생성하는 CRUD 실습할때까지만 해도 문제없었는데, 갑자기 에러를 벹어내네요.. 3일동안 이 문제를 해결하려 힘써봤는데 도저히 감이 안잡혀서 질문드립니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
nextTick, promise 우선순위
강의 부분 : 3-6강 5:46초영상에는 nextTick이 promise보다 우선해서 console에 찍히게 되는데, 제가 직접코드를 실행시켜보니 promise가 nextTick보다 먼저 console로 찍혔습니다. 우선순위가 어떤것이 맞는 것인가요??코드setImmediate(()=>{ console.log('immediate');})process.nextTick(()=>{ console.log('nextTick');});setTimeout(()=>{ console.log('timeOut');},0);Promise.resolve().then(()=>console.log('promise')); 출력결과혹시 몰라 여러번 컴파일 했는데도 결과가 같게 나옵니다:)
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
제로초스쿨 커뮤니티 슬랙에 들어갈수없습니다....!
안녕하세요, 제로초 스쿨 커뮤니티 에 들어갈 수 없는데..... 이제 슬랙을 운영하시지 않으시는건가요 ??
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
res.end() 앞 return 여부의 차이
아래는 res.end()앞에 return이 없는 경우입니다.http.createServer(async (req, res) => { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); const data = await fs.readFile('./http.html'); res.end(data); } 아래는 res.end()앞에 return이 없는 경우입니다.http.createServer(async (req, res) => { const data = await fs.readFile('./restFront.html'); res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end(data); // res.end() 앞에 return이 있음. }위 예시 말고도 코드 여러 군데에서 어떤건 return 이 들어가고 안들어가고 하더라고요. return이 있고 없고에 어떤 차이가 있는 걸까요?감사합니다.
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
PPT 파일을 받을 수 있나요?
어디서 받아야 하는지 찾아도 안보여요 ㅠㅠ
-
[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
호출스택에 아무것도 없을 때 백그라운드에서 테스트큐로 넘어가는 건가요?
호출스택에 아무것도 없을 때백그라운드에서 테스트 큐로 넘어가는건가요?아니면 테스트큐에서 호출스택으로 가는건가요?