라우터에서 읽어온 json파일 ejs에서 받기
fs로 json파일을 읽어오면 object가 아니라 string상태인데 이걸 그대로 보내면 ejs에서 파싱이 되지 않는다. 파일을 읽어온 후 한번 parse했다가 다시 stringify해서 보내야한다 const router = require('express').Router(); const fs = require('fs'); let json = {}; fs.readFile('routes/data.json', 'utf8', function (err, data) { console.log(err); console.log(JSON.parse(data)); json = JSON.parse(data); }); router.get('/', (req, res, next) => { res.render('url', { da..
Node.js
2020. 11. 24. 15:04

1-1. Node.js 설치 1-2. nodejs express 설치 1-2-1. npm -v 로 npm이 설치되어있는지 확인 1-2-2. npm install express -g 로 express를 설치한다 1-2-3. npm intall express-generator -g 로 express-generator를 설치한다 1-2-4. express 앱이름 로 프로젝트를 생성한다. 1-2-5. ejs로 project를 생성한다 1-2-6. npm install 로 모듈 설치 1-2-7. npm start 로 서버를 실행한다
Node.js
2020. 8. 4. 22:14