nodejs 학습 자료 - 1 절: helloword 설치 및 실행!

1334 단어
설치 하 다.
https://nodejs.org/en/download/ 설치 패키지 권장
  • 명령 행 방식
  • yum install -y gcc-c++ make
    curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
    
    yum -y install nodejs
    yum -y install nodejs npm
    
  • 설치 충돌 시 설치 삭제 권장
  • yum remove nodejs npm -y
    
    -     
    /usr/local/lib
    /usr/local/include
    
  • 업그레이드
  • $ sudo npm install npm -g
    

    테스트 환경 helloword
  • 새 파일 helloword. js
  • console.log("helloword!");
    
  • 운행
  • $ node helloword.js
    
  • 출력
  • helloword
    

    웹 서버 만 들 기
  • 새 파일 웹 서버. js
  • var http = require("http")
    http.createServer(function(request, response){
      response.writeHead(200,{'content-Type':'text/plain'});
      response.end('hello word!');
    }).listen(8888);
    
    console.log('web server is running! http://127.0.0.1:8888/');
    
    require 호출 http 모듈 서비스 listen 감청 8888 포트
  • 운행
  • $ node webserver.js
    
  • 출력
  • 브 라 우 저 입력http://127.0.0.1:8888/
    레 퍼 런 스
    https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/
    코드
    https://github.com/hans007/JavaScriptCodes/tree/master/nodejs-do

    좋은 웹페이지 즐겨찾기