여백에 도장 찍기

Node.js 설치 및 실행 본문

Node.js

Node.js 설치 및 실행

Linzyseo 2022. 1. 11. 10:46

1. brew를 통해 Node.js 설치 

>>> brew install node
>>> node -v                                                                                                              10:35.30 화  1 11 2022 >>>
v17.3.0
>>> npm -v                                                                                                               10:35.33 화  1 11 2022 >>>
8.3.0

 

2. 간단하게 Node.js 실행해보기 

>>> mkdir ~/projects
>>> cd ~/projects
>>> vi hello-world.js
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!\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

>>> node hello-world.js
Server running at http://127.0.0.1:3000/

 

 

http://127.0.0.1:3000/ 호출 결과 

 

 

 

 

 

3. 참조 

https://nodejs.org/api/synopsis.html

 

Usage and example | Node.js v17.3.1 Documentation

Usage and example# Usage# node [options] [V8 options] [script.js | -e "script" | - ] [arguments] Please see the Command-line options document for more information. Example# An example of a web server written with Node.js which responds with 'Hello, World!'

nodejs.org

 

 

'Node.js' 카테고리의 다른 글

yarn install  (0) 2022.01.11
Comments