Server & Node - Node.js

Verba volant, scripta manent·2021년 2월 10일

Node.js란?

노드는 Chrome V8 엔진으로 만들어진 자바스크립트 런타임이다.
여기서 V8은 자바스크립트를 기계어로 컴파일 해주는 것을 뜻하며 런타임이란 프로그래밍 언어가 구동되고 있는 환경을 뜻한다.

=> 자바스크립트를 컴파일 해주는 엔진으로 빌드 된 자바스크립트가 구동중인 환경이다.

이벤트 기반 및 논블로킹 I/O 모델

유저의 클릭이나 네트워크에 리소스를 요청하는 이벤트가 논블로킹으로 이루어지는 Input Output model이다.

Node.js의 특징

1. javascript를 컴파일 하여 구동한다.

2. 이벤트 기반의 non blocking 모델로 속도가 빠르다.

3. 별도의 설치를 하지 않아도, node 상에서 쓸 수 있는 모듈이 있다.

Node core modules

node와 함께 번들링 되어있는 모듈로, require('') 방식으로 사용할 수 있다.
ex1) fs, http, url, path
ex2)

const fs = require('fs')
const http = require('http')

fs.readFile('./something.json',(err,data)=>{
    console.log(data);
})

http.get('http://localhost:5000/api',(res)=>{
    console.log(res)
})

NPM이란?

풀네임은 Node Package Manager.
세계에서 가장 큰 오픈소스 라이브러리 생태계 중 하나

NPM의 편리성

ex)
before

<html>
    <head>
        <script src="https://code.jquery.com/jquery-2.x-git.min.js"></script>
    </head>
    <body>
        <script>
            $('button').on('click',function () {})
        </script>
    </body>
</html>

after

const $ = require('jqery')

$('button').on('click',function() {
    console.log('button clicked!!!')
})

그리고 package.json에 그 정보들이 모두 담겨있다.

{
  "name": "hello",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "jquery": "^3.3.1"
  }
}
profile
말은 사라지지만 기록은 남는다

0개의 댓글