본문 바로가기

STUDY

(287)
Node.js | Express generator 간단 구조 파악 + PM2사용 ※Express generator 이전 글 참고 우선, Express generator를 이용한 프로젝트 기본 구조(view의 형식을 ejs로)를 생성합니다. $ npm express 프로젝트명(폴더명) --view=ejs Express generator로 생성된 기본 구조를 간!단!히 알아보자면, bin/www: 포트번호, 서버가 생성되는 곳 public: css, image, javascript 등 정적인 파일들을 담는 곳 routes: 라우터들을 관리하는 곳 views: view 파일들을 관리하는 곳 app.js: 미들웨어 부분 +) PM2 사용 package.json을 아래와 같이 수정해 줍니다. "start": "pm2 start ./bin/www", "stop": "pm2 stop ./bin/..
Node.js | MySQL 연동 ※ 현재 사용하고 있는 MySQL의 버전은 8.0.18버전으로, MySQL과 연동할 때 오류가 발생할 수 있다. 이유는 이전 버전과 최신 버전의 비밀번호 형식이 변경되어서 라고 하는데... 아래 링크를 참고하면 해결 가능하다. MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client I am a node.js and MySQL beginner and I just started setting up and trying out some basic code. However, I can't make even a simple connection to the server f..
MySQL | 테이블 수정(ALTER TABLE) 앞서 만든 테이블의 CONTENT컬럼의 데이터타입을 변경(VARCHAR -> TEXT)하고 싶어졌다. 테이블의 컬럼 수정 ALTER TABLE 테이블이름 MODIFY 컬럼명 변경내용; 변경이 잘 적용되었나 확인 SHOW CREATE TABLE 테이블명; +) 참고: 테이블을 수정(ALTER TABLE)에 관한 여러 예제를 확인할 수 있다. MySQL :: MySQL 8.0 Reference Manual :: 13.1.9.3 ALTER TABLE Examples 13.1.9.3 ALTER TABLE Examples Begin with a table t1 created as shown here: CREATE TABLE t1 (a INTEGER, b CHAR(10)); To rename the table fr..
MySQL | 스키마(데이터베이스) 생성 및 테이블 생성 참고한 공식 document MySQL :: MySQL 8.0 Reference Manual :: 3.3.1 Creating and Selecting a Database 3.3.1 Creating and Selecting a Database If the administrator creates your database for you when setting up your permissions, you can begin using it. Otherwise, you need to create it yourself: mysql> CREATE DATABASE menagerie; Under Unix, database names are dev.mysql.com 우선, commend로 MySQL을 실행해줍니다. mysq..
MySQL | 설치 및 환경변수 설정 (MySQL 8.0.18) 1. MySQL 다운로드 MySQL :: MySQL Community Downloads The world's most popular open source database dev.mysql.com 상단에 첨부한 링크로 이동하세요. 2. MySQL 설치 요약: Next / Execute / Finish의 반복! Finish버튼을 누르면 Workbench와 Shell이 시작됩니다. +) 설치가 잘 되었는지 확인 3. 환경변수 설정 환경변수를 설정하면 모든 디렉터리에서 MySQL에 접근할 수 있게 됩니다. MySQL이 설치된 폴더(C드라이브의 Program Files)에 들어가 mysql.exe가 있는 폴더를 찾습니다. +) 환경변수 설정이 잘 되었나 확인하기 위해 데이터베이스 서버에 접속해 봅시다. comme..
Node.js | Express application generator Express application generator Express application generator Use the application generator tool, express-generator, to quickly create an application skeleton. You can run the application generator with the npx command (available in Node.js 8.2.0). $ npx express-generator For earlier Nod expressjs.com application generator를 사용하면 빠르게 프로젝트에 필요한 기본 뼈대를 자동으로 생성해줍니다. 매우 편 리 한 것... 새로운 프로젝트를 만들 때 마다 vie..
Node.js | Express Router (라우터 분리하여 관리하기) Node.js의 프레임워크인 Express에서는 Router를 따로 분리하여 관리할 수 있다. 공식 document를 살펴보면 1. 분리해서 관리할 router들을 모아놓는 파일에 express 모듈을 추가하고, express 내의 Router를 이용 변수명을 router로 써서 그렇지 기존에 쓰던 app이랑 똑같다고 생각하면 쉽다. var express = require('express'); var router = express.Router(); 2. 이 파일을 모듈로서 사용하기 위해 exports해주기 파일의 맨 마지막 줄에 이 코드를 작성해주어야 사용이 가능해진다. module.exports = router; 간단히 사용해보면 route들의 개수가 늘어나도 파일을 분리하여 쉽게 관리가 가능하다! +..
Node.js | Express Middleware사용하기 (body-parser) body-parser 말그대로 body를 parsing해주는 미들웨어. 들어온 데이터를 원하는 형태로 변환해준다고 생각하면 됨 body-parser 없이도 post로 보낸 값을 받아올 수 있지만, body-parser를 사용함으로써 더 간단한 코드를 작성할 수 있게된다. install한 body-parser를 장착 var bodyParser = require('body-parser') 그리고 app.use(bodyParser.urlencoded({ extended: false })) 위의 코드 한 줄이면 request.body에 접근해 데이터를 가져올 수 있게 됩니다. 간단히 사용해보았음 이게 POST 방식일 때만 해당되는 것 인가..? 아마 GET 방식의 값을 받을 땐 req.query를 사용하면 될 ..