호그래머

라즈베리파이4(Raspberry Pi 4 Model B) Node.js(V12.18.3) 설치 20.08.02 본문

Raspberry Pi

라즈베리파이4(Raspberry Pi 4 Model B) Node.js(V12.18.3) 설치 20.08.02

호그래머 2020. 8. 2. 13:35
728x90

라즈베리파이 Node.js 설치

1. sudo apt-get update

2. sudo apt-get install curl (이미 설치 됨)

3. curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

12.18.3버전 설치

4. sudo apt-get install nodejs

5. 설치 완료 확인

nodejs -v

Node.js 버전 확인

npm -v

npm 버전 확인

 

6. 간단예제 실행(웹 서버)

소스코드 - hello_world.js

const http = require('http');

const hostname = '192.168.0.7';
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}/`);
});

hellow_world.js 라즈베리파이 pi폴더로 이동

node hello_world.js 명렁으로 실행

웹브라우저에서 hello_world 서버 접속 192.168.0.7:3000

1. 라즈베리파이에 Node.js를 설치하였습니다.

2. npm은 패키지 관리자 입니다.

2. 현재 Node.js 최신 버전은 14.x 안정적 지원 버전은 12.x 입니다.

3. 짧은 소스코드로 웹서버를 단시간안에 구축할 수 있습니다.

 

참고링크

https://nodejs.org/ko/

https://github.com/nodesource/distributions/blob/master/README.md

https://nodejs.org/dist/latest-v12.x/docs/api/synopsis.html

https://www.npmjs.com/

 

728x90
Comments