목록2024/08/11 (5)
wintertreey 님의 블로그
place table과 user table에 대해 칼럼을 짜던 중 고민거리가 생겼다. 좋아요 like에 대해서 보여주기 위해, 어느 테이블에 어떤 칼럼이 필요할까?? 우선 내가 구현하고자 하는 기능은 다음과 같다. 1. 사용자가 좋아요한 장소 조회(마이페이지)2. 장소별 좋아요 수(장소 상세페이지) 1. 사용자가 좋아요 한 장소 조회 place 테이블에 p_like boolean으로 가능.p_like 칼럼의 값이 true일 때 해당 장소가 찜된 것으로 간주되므로, 별도의 칼럼 없이도 원하는 기능을 구현할 수 있습니다. 2. 장소별 좋아요 수place 테이블에 like_cnt 칼럼이 필요했다. user 테이블이 아닌 place 테이블에 해당 칼럼을 둠으로써, 효율성, 데이터 집계, 데이터 유지와 업..
경로세팅하기//환경변수 PORT가 존재하면 그 값을 사용하고, 아니면 3000사용하겠다는 의미.app.set('port', process.env.PORT || 3000);// 현재 폴더를 지정 : __dirname을 ECM(ECMAScript Module)환경에서 사용하기const __filename = fileURLToPath(import.meta.url); //현재 실행중인 파일경로const __dirname = path.dirname(__filename); //현재 실행 중인 폴더 경로 라우팅처리app.get(요청, 라우칭처리)app.get('/', function(req, res){ res.send('아우넘졸리다 으악❄️❄️');});app.get('/java', function(req, r..
http 모듈http모듈은 Node.js에서 가장 기본적이고 중요한 웹 모듈입니다. 웹서버와 클라이언트 생성등 관련된 모든 기능을 담당합니다. import http from 'http'; //웹 관련 모듈http.createServer((req, res) => { res.writeHead(200, {'Content-Type':'text/html;charset=utf-8'}); res.write('환영합니다. 노드 서버 세상에 오신것을'); res.write('반가워요'); res.end('Hello~'); //응답종료 //res.write('헬로헬로');}).listen(8080, () => { console.log('서버 서비스중...');}); 터미널에서 서버를 켜고..
Event 모듈Node.js 에선 Event를 매우 많이 사용하고, 이 때문에 다른 비슷한 기술들보다 훨씬 빠른 속도를 자랑합니다.Node.js 기반으로 만들어진 서버가 가동되면, 변수들을 initialize 하고, 함수를 선언하고 이벤트가 일어날때까지 기다립니다.이벤트 위주 (Event-Driven) 어플리케이션에서는, 이벤트를 대기하는 메인 루프가 있습니다.그리고 이벤트가 감지되었을시 Callback함수를 호출합니다. 이벤트가 콜백과 비슷해 보일 수 도 있습니다.차이점은, 콜백함수는 비동기식 함수에서 결과를 반환할때 호출되지만,이벤트핸들링은 옵저버 패턴에 의해 작동됩니다. 이벤트를 대기하는 (EventListeners) 함수들이 옵저버 역할을 합니다.옵저버들이 이벤트를 기다리다가, 이벤트가 실행되..
Node File System 모듈파일시스템 모듈이란, 파일 처리와 관련된 작업을 하는 모듈로 보통 FileSystem을 줄여서 fs 모듈이라고 줄여 부릅니다.노드에서 가장 많이 쓰이고 중요한 모듈 중 하나입니다. fs 모듈에는 대부분의 메소드들이 동기/비동기로 나뉘는데, Sync라는 이름이 붙어있는 메소드가 동기방식을 사용한다고 보면 됩니다.동기적 읽기 방식을 사용하면 파일을 읽으면서 다른 작업을 동시에 할 수 없습니다.하지만 비동기적으로 읽으면 파일을 읽으면서 다른 작업도 동시에 수행할 수 있고, 파일을 다 읽으면 매개변수 callback으로 전달한 함수가 호출됩니다.주로 비동기적 형식을 많이 사용하지만, 서버 시작 시 세팅 파일을 읽는 작업과 같이 동기적 형식이 더 적절한 경우도 있습니다. 동..