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

자바스크립트

by 쭈잇 2019. 7. 3.

Contents

    반응형

    yum install epel-release

    yum install npm nodejs

     

     

    vi hello.js

     console.log('Hayo');

    node hello.js

     

    --------------------------------

    // node.js의 http모듈을 변수 http로 추출합니다.
    var http = require('http');

    var hostname = '127.0.0.1';
    var port = '9999';

    // http모듈의 createServer 함수를 호출하여 서버를 생성합니다.
    // req: request. 웹 요청 매개변수, res: response. 웹 응답 매개변수
    httpd = http.createServer(function (req, res) {
        // writeHead: 응답 헤더를 작성합니다.
        // 200: 응답 성공, text/html: html문서
        res.writeHead(200, {'Content-Type': 'text/html'});
        // end: 응답 본문을 작성합니다.
        res.end('Hello World111');

    // listen: 매개변수로 포트와 호스트를 지정합니다.
    })

    httpd.listen(port, hostname,
    function(){
        console.log(`Server running at http://${hostname}:${port}/`);
    });

     

    ----------------------------

    node httpd.js

     

     

    new 를 시용해서 하면 Object 타입이다

    object 타입은 확장이 가능하다

     

     

    // 내장타입의 객체는 확장이 불가능하다

    n.mVal=20;

    console.log(n.mVal);

     

    // 객체타입의 객체는 확장이 불가능하다

    n2.mVal=20;

    console.log(n2.mVal);

     

    null 과 undefined 차이

     

     

     

     

     

    변수 범위

     

    var 을 함수내부에서 사용하면 지역변수 

     

     

     

     

     

     

     

     

     

    반응형