본문 바로가기
300x250

Web/Node.js5

mac에서 node.js 설치하기. 리액트 JS 설치하려면 node.js가 설치 되어 있어야 하기에 우선 node.js 설치하는 방법을 포스팅합니다. 터미널에서 아래와 같이 nvm을 설치합니다. brew install nvm 그리고 나서 nvm 환경설정을 해줍니다. vim ~/.zshenv export NVM_DIR="$HOME/.nvm" [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" 그리고 나서 터미널을 재실행 후 아래의 명령어를 쳐서 nvm이 정상적으.. 2022. 9. 27.
[Node.js] 웹 서버 만들기 웹 서버 만드는 코드 입니다. 같은 폴더에 index.html 파일을 넣어주고 app.js 라는 파일을 생성 후 아래의 코드를 작성합니다. var http = require('http'); var fs = require('fs'); var app = http.createServer(function(request,response){ var url = request.url; if(request.url == '/'){ url = '/index.html'; } if(request.url == '/favicon.ico'){ return response.writeHead(404); } response.writeHead(200); response.end(fs.readFileSync(__dirname + url)); .. 2021. 1. 31.
[Node.js] 파일 쓰기 비동기식으로 파일 쓰기 방법 입니다. var file = require('fs'); file.writeFile('./output.txt', 'TEST', function(err){ if(err){ console.log("Error: " + err); } console.log("파일 쓰기 완료"); }); 2021. 1. 31.
[Node.js] 파일 읽기 동기식 파일 IO는 파일 작업이 끝날 때까지 대기합니다. var file = require('fs'); var data = file.readFileSync('./package-lock.json', 'utf-8'); console.log(data); 비동기식 파일 IO는 파일 작업을 요청만 하고 바로 그 다음 작업을 수행합니다. 비동기식으로 파일을 읽는 것이 더 자주 사용되는 패턴 입니다. 비동기식으로 실행할 경우 파일을 읽은 것보다 console.log('package.json 파일을 읽도록 요청했습니다.'); 이 콘솔이 더 먼저 출력됩니다. var file = require('fs'); file.readFile('./package-lock.json', 'utf8', function(err, data){.. 2021. 1. 31.
300x250