본문 바로가기
카테고리 없음

[JavaScript] express

by 왹져박사 2023. 5. 24.
728x90

dir 설정 후 

npm init

npm i express

 

https://www.npmjs.com/package/express

 

express

Fast, unopinionated, minimalist web framework. Latest version: 4.18.2, last published: 8 months ago. Start using express in your project by running `npm i express`. There are 72203 other projects in the npm registry using express.

www.npmjs.com

 

설치 완료되면 

node_modules 폴더 생김

nodemon - 스크립트를 수정했을 경우 서버를 재시작하지 않아도 반영

 

https://www.npmjs.com/package/nodemon

 

nodemon

Simple monitor script for use during development of a Node.js app.. Latest version: 2.0.22, last published: 2 months ago. Start using nodemon in your project by running `npm i nodemon`. There are 4583 other projects in the npm registry using nodemon.

www.npmjs.com

npm install -D nodemon

추가

"start:dev": "nodemon app.js"

npx nodemon

성공

추가

process.env.PORT가 있다면 사용하고 없으면 8080
 

 

미들웨어

 

 

    res.sendFile(__dirname + '/index.html');
 

현재 디렉토리 안의 public폴더에 있는 파일을 알아서 찾아줌. 

https://expressjs.com/ko/guide/routing.html

 

Express 라우팅

라우팅 라우팅은 애플리케이션 엔드 포인트(URI)의 정의, 그리고 URI가 클라이언트 요청에 응답하는 방식을 말합니다. 라우팅에 대한 소개는 기본 라우팅을 참조하십시오. 다음 코드는 매우 기본

expressjs.com

라우터도 미들웨어의 일종. 

일반적인 미들웨어 + 라우터 + 에러 미들웨어 로 구성되는 듯하다. 

 

라우터의 서로 다른 요청

localhost:8080/user/hye

localhost:8080/

 

 

mysql

https://www.npmjs.com/package/mysql

 

mysql

A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.. Latest version: 2.18.1, last published: 3 years ago. Start using mysql in your project by running `npm i mysql`. There are 7194 other projects i

www.npmjs.com

 

728x90