[오늘의 공부]/Node.js & package manager
[오늘의 node.js & npm] React를 Node 웹 서버를 통해 출력하기
개피곤씨
2023. 3. 5. 01:45
react 폴더에서...
일단 빌드를 합니다
npm run-script build
node 프젝 안의> index.js(뭐 server.js등등...)
express서버에서 빌드 완료된 리액트 작업물 실행
const express = require('express');
const path = require('path');
const app = express();
const port = 5000;
app.use(express.static(path.join(__dirname, '../react/build')))
app.listen(port, () => {
console.log(`Server app listening on port ${port}`);
})
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '../react/build/index.html'));
}) //빌드 폴더안에 있는거 가져오세요~