[nodejs] 1. nodejs Getting start, 서버 구현하고 Hello world 띄어보기
2023. 11. 24. 20:40ㆍcs및 소프트스킬/nodejs
728x90
반응형
SMALL
이번 시간에는 nodejs를 직접 시작해보겠습니다.
nodejs를 "Hello world"를 띄우고, 구동원리의 대해 알아보겠습니다.
https://github.com/BerkleyLim/basic_nodejs
GitHub - BerkleyLim/basic_nodejs: 이 프로젝트는 node.js 입문을 위한 프로젝트 중 하나입니다.
이 프로젝트는 node.js 입문을 위한 프로젝트 중 하나입니다. Contribute to BerkleyLim/basic_nodejs development by creating an account on GitHub.
github.com
1. 소스코드
<ver01/app.js>
// http 라이브러리 연동
const http = require('http');
// 서버 주소, 포트 지정
const hostname = '127.0.0.1';
const port = 300;
// 서버 설정
const server = http.createServer((request, response) => {
response.statusCode = 200; // 상태 코드
response.setHeader('Content-Type', 'text/plain'); // 헤더 설정
response.end('Hello Worlds'); // 화면에 띄울 페이지
})
// 서버 실행
server.listen(port, hostname, () => {
// 콘솔에 창을 띄어줍니다.
console.log(`Server running at http://${hostname}:${port}`)
})
2. 실행
node ver01/app.js
3. 결과

<코드 설명>
- app.js를 생성하여 node.js 서버를 만들어줍니다.
- 다음은 http를 임포트하여 지정하고, port, host IP 주소를 지정합니다.
- http 라이브러리를 이용하여 createServer를 이용하여 server 설정
- 이후, 서버 구동 실행
해당 코드는 Github 링크 타고, Ver01 을 참조하시기 바랍니다.
728x90
반응형
LIST
'cs및 소프트스킬 > nodejs' 카테고리의 다른 글
| [nodejs] 6. 프론트엔드 샘플 html을 테스트로 만들고, nodejs 연동하기 (0) | 2023.11.28 |
|---|---|
| [nodejs] 5. nodejs + express 프로젝트 구성하여 리팩토링 (0) | 2023.11.26 |
| [nodejs] 4. express에 각 경로별로 출력될 view단 나타내기 (0) | 2023.11.25 |
| [nodejs] 3. express framework에서 router 적용 (0) | 2023.11.24 |
| [nodejs] 2. express Framework 도입 (router 적용 x) (2) | 2023.11.24 |