내맘대로 살기🎉

[Node.js] express의 hello word 예제 (..syntax highlighter 사용법) 본문

개발자의 길/Node.js

[Node.js] express의 hello word 예제 (..syntax highlighter 사용법)

해림😶 2017. 4. 25. 23:05



Hello word예제.


http://expressjs.com/ko/starter/hello-world.html


             *가장 최초로 실행될 파일을 메인(엔트리)파일이라고 한다. 


var express = require('express');

var app = express();


위의 두 줄은 그냥 형식이라고 생각해도 된다.


vim xxx.js라는 형식으로 터미널에서 js파일을 편집한다.

따로 명령어가 있으니, 참고할 것.

생활코딩 : https://opentutorials.org/course/730/4561


저장 -> :w

실행 종료 -> :q

글쓰기 -> a

명령어 쓰기 -> esc버튼


app.get('/',function(req, res){

res.send('here');

});


위의 here에 값을 입력하면 홈페이지 here 메시지가 출력.


app.get('/login',function(req, res){

res.send('there');

});

위의 값과 같이 작성하고, http://127.0.0.1:3000/login로 접속하면 there 메시지가 출력.


get이라는 메소드를 "라우터"라고 부른다.            *Router - 길을 찾다.

get은 라우팅을 한다.


- get의 역할을 보여주는 마인드 맵.   



이렇게 send()안에 html 태그를 삽입할 수 있음.

위의 코드는 기본 문이니 외우자.


* syntax highlighter 사용법


<textarea name="code" class="brush:사용언어;">

이 안에 코드 삽입.

</textarea>

반응형
Comments