본문 바로가기

NodeJS

(33)
Node.js Gulp란 아래 블로그 참고~ 1) https://haeguri.github.io/2019/03/31/introduction-gulp/ Haeguri Devlog 공유하고 싶은 것들을 정리한 공간입니다. haeguri.github.io 2) https://worker-k.tistory.com/entry/Gulp-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0 Gulp 설치하고 시작하기 Gulp 설치하기 gulp를 사용하기 위해서는 node.js 를 다운로드 받으셔야 합니다. window + R 키를 함께 눌러 cmd를 입력한 뒤 cmd 창에서 아래와 같이 노드와 npm 버전을 확인하는 명령어를 입력 합니다. no worker-k.tistory.com 3) https://gulpjs.com/docs..
Atom에서 pug emmet 안될 때 emmet pug atom 라고 검색했을 때, 다행히 아래 사아트가 바로 눈에 띄어서 도움 받았습니다. 참고 : https://github.com/emmetio/emmet-atom/issues/354 Emmet to Jade in Atom? · Issue #354 · emmetio/emmet-atom I see that Emmet can output Jade but when I try in Atom, it doesn't seem to do anything. To straight HTML works fine. Is there anyway to make this work? Thanks! github.com 스크롤 내려서 엄청 아랫 부분에 있는 이 부분이 도움됐습니다. Atom에서 pug emmet 안될 때...
express 미들웨어 const express = require("express"); const app = express(); const port = 3000; // 별도의 다른 모듈을 쓰지 않고 GET 라우트 정의 방법과 콜백 함수를 제공. app.get('/', (req, res) => { res.send("Hello express module"); // send 모듈은 http 모듈의 write와 비슷한 역할. }); app.listen(3000, () => { console.log(`Server is running port ${port}!`); }); Express는 http 모듈도 지원한다. wirte를 사용했다면 반드시 end로 마무리 해야 하는 것을 잊지 말기. 미들웨어 Express와 같은 웹 프레임워크는 보통..
response 객체 메소드 res.download() : 파일이 다운로드 되도록 프롬프트 res.end() : 응답 프로세스를 종료 res.json() : json 응답을 전송합니다. res. jsonp : jsonp 지원을 통해 json 응답을 전송합니다. res.redirect() : 요청의 경로를 재지정합니다. res.render() : 템플릿을 랜더링합니다 res.send() : 다양한 유형의 응답을 전송( 문자열 HTML, 객체 JSON, 배열 JSON의 형태) res.sendFile() : 파일 전송 res.sendState() : 응답 상태 코드를 설정한 후 해당 코드를 문자열로 표현한 내용을 응답 본문으로 전송합니다.
Node.js 폴더에 파일 존재 유무 확인하기 Node.js에서 반드시 모듈 fs를 require를 해야합니다. const fs = require('fs'); 폴더 구조 : 의도 : type폴더 안의 A-1 ~ C-4 폴더안에 있는 png 파일의 유무를 알고싶었습니다. png 파일의 이름은 폴더의 이름과 같습니다. ex) /public/type/A-1/A-1.png const tDir = __dirname + '/../public/type/'; fs.readdir(tDir, (err, data)=>{ if(err) throw err; data.forEach((item, i) => { const imgFile = tDir+item; // console.log(imgFile+"/"+item+".png"); fs.exists(imgFile+"/"+item..
Node.js에서 index.html 파일 읽어서 code 태그에index.html파일 뿌리고 highlightjs 적용시키기 개인 프로젝트 사이트에 소스코드를 보여주어야 할 부분이 생겨서 적용했습니다. index.html파일과 style.css, script.js파일을 각각 fs.readFile로 읽어들이고 파일 내용을 string 변수에 담습니다. 그리고 string을 그대로 pug로 가져가서 뿌려줍니다. 뿌려질 때 코드가 줄바꿈이 되지 않고 일직선으로 보이기 떄문에 hightlight를 적용시켰습니다. highlightjs.org/ highlight.js Version 10.3.2 Tiny tiny release, just to fix the website incorrectly not listing Javascript in the list of languages you could choose for a custom buil..
cafe24 Node.js 호스팅 사용시 503에러 error 해결방법 Node.js로 개발하면서 cafe24 Node.js 호스팅을 사용중입니다. 로컬에서는 문제가 없었는데, 자꾸 503에러가 나는 것이였어요. Error 503 Service Unavailable Service Unavailable Guru Meditation: XID: 192392972 Varnish cache server 그리고 로그를 살펴보면 toString에 뭔가 문제가 있다고 했었어요. TypeError: Cannot read property 'toString' of undefined at ReadFileContext.callback (/home/hosting_users/아이디/apps/앱이름/routes/index.js:8:37) at FSReqCallback.readFileAfterOpen [..
pug json파일 읽어서 pug로 던지고 뿌리기 node.js에서 express로 간편하게 잡고, view파일은 pug로 사용중인데 DB사용까진 안해도 될거 같아서 json으로 작성한뒤 pug index파일로 뿌리려고 하는데~ 엄청나게 안되다가 해결했습니다. 눈물날거 같군... js/example.json [ { "thumbnailImg" :"/img/thumbnailImg01.jpg", "cardText" : "카드 텍스트 1", "cardTextNum" : "A-1", "textMuted" : "2020-11-09" }, { "thumbnailImg" :"/img/thumbnailImg02.jpg", "cardText" : "카드 텍스트 2", "cardTextNum" : "A-2", "textMuted" : "2020-11-10" } ] rout..