티스토리 뷰

1. eclipse에서 프로젝트를 생성합니다.

2. 아래와 같이 'nodeTest'라는 이름의 프로젝트가 생성되었습니다.

3. Teminal을 열고  프로젝트 폴더로 이동합니다.

4. 'npm init' 입력하여 package.jason 파일을 생성합니다.

5. 'npm install express' 입력하여 express 모듈을 설치합니다.

6. 이클립스에서 프로젝트 내에 'index.js' 파일을 생성합니다.

7. index.js 파일에 다음과 같이 붙여 넣습니다.

var app = require('express')();
var http = require('http').Server(app);

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});


http.listen(3000, function(){
  console.log('listening on *:3000');
});

8. 이클립스에서 프로젝트 내에 'index.html' 파일을 생성합니다.

9. index.html 파일에 다음과 같이 붙여 넣습니다.

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
    <title>Hello! Node.js</title> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
</head> 
<body>
    This is a sample page.
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/js"></script>     
</body> 
</html>

10. 커서를 index.js의 파일 내에 두고 이클립스의 실행 버튼을 누르면 console에 아래와 같이 결과가 프린트됩니다.

11. 웹 주소창에 'localhost:3000'을 입력하고 실행하면 아래와 같이 웹사이트 서버가 만들어진 것을 확인할 수 있습니다.

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

Node.js 설치하기(mac)  (0) 2022.03.07
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함