728x90
โ Node.js ์ค์น
์ฐ์ homebrew๋ก Node.js๋ฅผ ์ค์นํด์ฃผ์๋ค.
brew install node
โ ์ฝ๋ ์์ฑ
๋จผ์ ๊ฐ๋จํ ์น์๋ฒ๋ฅผ ๋์๋ณด๊ธฐ ์ํด index.js ํ์ผ์ ์์ฑํ๋ค.
const http = require('http');
http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello Node.js');
}).listen(9090);
์คํ์ ์ด๋ ๊ฒ ํ๋ฉด ๋๋ค.
node index.js
node.js ์๋ฒ ๋ ํ๊ธฐ ์ํด node-red express๋ฅผ ์ค์นํด์ฃผ์๋ค.
npm install node-red express
์ ํ๋ฆฌ์ผ์ด์ ์ฝ๋์ธ nodered.js๋ฅผ ์๋์ฒ๋ผ ์์ฑํด์ฃผ์๋ค.
const express = require('express');
const http = require('http');
const RED = require('node-red');
const app = express();
const server = http.createServer(app);
const settings = {
httpAdminRoot: "/red", // ํธ์ง ํ๋ฉด ๊ฒฝ๋ก
httpNodeRoot: "/get", // API ๊ฒฝ๋ก
userDir: "./nodered/", // Node-RED ์ค์ ๋๋ ํ ๋ฆฌ
flowFile: "flows.json", // ํ๋ก์ฐ ํ์ผ ์ด๋ฆ
functionGlobalContext: {}, // ๊ธ๋ก๋ฒ ํจ์ ์ปจํ
์คํธ
};
RED.init(server, settings);
app.use(settings.httpAdminRoot, RED.httpAdmin);
app.use(settings.httpNodeRoot, RED.httpNode);
server.listen(8081, () => {
console.log("์๋ฒ๊ฐ 8081 ํฌํธ์์ ์คํ ์ค์
๋๋ค.");
});
RED.start();
์์ฑํ ํ์ผ์ ์คํํด์ฃผ์๋ค.
node nodered.js
โ ์๋ฒ ์ ์
localhost:8081/red ๊ฒฝ๋ก๋ก ์ ์ํ๋ฉด ๋๋ค. (๋ํดํธ๋ก /red ๊ฒฝ๋ก๊ฐ ๋ ธ๋๋ ๋ ํธ์ง๊ธฐ์ด๋ค.)
728x90
'๊ฐ์ธ ๊ณต๋ถ > WEB' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
WAS (์น ์ ํ๋ฆฌ์ผ์ด์ ์๋ฒ) (0) | 2025.01.13 |
---|---|
@ExceptionHandler, @ControllerAdvice (0) | 2024.03.01 |
@SessionAttribute, @SessionAttriubtes (2) | 2024.03.01 |
@ModelAttribute (0) | 2024.03.01 |
[๊ฐ์ ์ ๋ฆฌ] ์คํ๋ง MVC ํ์ฉ (1) | 2024.02.29 |