본문 바로가기
풀스택/Node js

1. node js - ex01

by woohyun22 2019. 4. 8.


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const http = require('http');
const express = require('express');
 
const port = 3000;
const app = express();
const router = express.Router();
 
app.use('/', router.get('/'function(req, res){
    res.send('Hello World');
}))
 
const server = http.createServer( app );
server.on('error', onError);
server.on('listening', onListening);
server.listen(port);
 
 
function onError(error){
    if (error.syscall !== 'listen') {
        throw error;
    }
 
    const bind = typeof port === 'string'
        ? 'Pipe ' + port
        : 'Port ' + port;
 
    // handle specific listen errors with friendly messages
    switch (error.code) {
        case 'EACCES':
            console.error(bind + ' requires elevated privileges');
            process.exit(1);
            break;
        case 'EADDRINUSE':
            console.error(bind + ' is already in use');
            process.exit(1);
            break;
        default:
            throw error;
    }
}
 
function onListening(){
    const addr = server.address();
    const bind = (typeof addr === 'string') ?
        'pipe ' + addr :
        'port ' + addr.port;
    console.log( 'Listening on ' + bind);
}
cs



1. app.js 작성

- settings - languages &frameworks - node.js and npm     - codingassistance check


2.   new project - node.js express -view engine ejs

file -setting - language - javascript - 6->5


3. port 3000 로 접속

http://localhost:3000/ 로 접속시 hello world

밑의 에러 코드는 에러시


4. ctrl shift f10 젯브레인 컴파일

밑의 터미널에서

npm install express 로 인스톨 받아준다 - 파이썬이랑 비슷



    





728x90

'풀스택 > Node js' 카테고리의 다른 글

Node.js란  (0) 2019.04.18
4. node js - guestbook  (0) 2019.04.08
3. node js -emaillist  (0) 2019.04.08
2. node js - ex02  (0) 2019.04.08

댓글