hello world

Node.js 프레임워크 Express 본문

WEB/Node.js

Node.js 프레임워크 Express

sohyun_92 2020. 8. 7. 15:09
728x90

-EXPRESS 란 ? 

   Node.js를 위한 빠르며 간편한 프레임워크 (개발을 빠르고 손쉽게 !) 


-EXPRESS 설치 방법

expressjs.com/ko/starter/installing.html

 

Express 설치

설치 Node.js가 이미 설치되었다고 가정한 상태에서, 애플리케이션을 보관할 디렉토리를 작성하고 그 디렉토리를 작업 디렉토리로 설정하십시오. $ mkdir myapp $ cd myapp npm init 명령을 이용하여 애플�

expressjs.com

나는 git bash를 통해 설치 했다 .

1.폴더 생성

2.npm init

3. npm install --save express

 


-Express 기본 예제

var express = require('express');
var app = express(); //express 모듈을 실행 하면 app에 return 

app.get('/',function(req, res){
    //res : 응답에 대한 객체
    res.send('Hello home page');    
}); //get방식으로 접속한 사용자 ./ 로 들어온 ...

app.get('/login',function(req,res){
    res.send('로긘 Please');
}); 

app.listen(3000,function(){
    console.log('Connected 3000 port !');
}); //3000 포트 listen

위의 코드에서

get.('/') 는 라우터라고 하는데 사용자의 요청과 처리를 중개하는 역할을 한다.

여기서 send('Hello home page') , send('로긘 Please') 는 처리 부분 Controller 라고 한다.

 

 

git bash 설치 및 사용 : https://helloworld92.tistory.com/37?category=917353

 

 


 

 

'WEB > Node.js' 카테고리의 다른 글

Git Bash 로 node.js 실행 종료  (0) 2020.08.07
node.js 프로젝트 생성  (0) 2020.07.15
Eclipse 에서 Node.js 개발환경 만들기  (0) 2020.07.15
Comments