

NodeJS 는 자바스크립트 엔진에 기반해 만들어진 서버 사이드 플랫폼입니다.
비동기 이벤트 주도 JavaScript 런타임으로써 Node.js 는 확장성 있는 네트워크 애플리케이션을 만들 수 있도록 설계되었습니다. 다음 "hello world" 예제는 다수의 연결을 동시에 처리할 수 있습니다. 각 연결에서 콜백이 실행되는데 실행할 작업이 없다면 Node.js 는 대기합니다.
:: 출처 (https://nodejs.org/ko/about/)
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
node -v
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"start"스크립트가 시작점 -> npm run start 다음에 index.js가 실행
npm install express --save
Express.js는 Node.js의 핵심 모듈인 http와 Connect 컴포넌트를 기반으로 하는 웹 프레임워크다. 그러한 컴포넌트를 미들웨어(middleware)라고 하며, 설정보다는 관례(convention over configuration)와 같은 프레임워크의 철학을 지탱하는 주춧돌에 해당한다. 즉, 개발자들은 특정 프로젝트에 필요한 라이브러리를 어떤 것이든 자유롭게 선택할 수 있으며, 이는 개발자들에게 유연함과 수준 높은 맞춤식 구성을 보장한다.
- HTTP 요청 본문 파싱
- 쿠키 파싱
- 세션 관리
- URL 경로와 HTTP 요청 메서드를 기반으로 한 복잡한 if 조건을 통해 라우팅을 구성
- 데이터 타입을 토대로 한 적절한 응답 헤더 결정
:: 출처 (https://wikibook.co.kr/article/what-is-expressjs/)
다운 받은 dependencies들은 다 이 폴더에서 관리됨
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
:: (http://expressjs.com/en/starter/hello-world.html)
✉️ 다음 글에선 Mongo DB와 연결을 다뤄보도록 하겠습니당
Node는 센서를 구동할 때 잠깐 다뤄본 적이있는데 웹프레임워크로 이용하려니 몰랐던 부분이 많아서 더 강의가 재밌게 느껴지네용🧚
팬씨하네요