목록Server/Node.js (14)
써먹는 웹개발
※ 에러가 발생한 명령어 : npm install multer multer-s3 mongoose socket.io jsonwebtoken bcrypt aws-sdk npm install 중에 다음과 같은 에러 메시지가 발생했을때 해결방법 1. 에러메시지 npm ERR! Unexpected end of JSON input while parsing near '...cj8HWt2uuTCks2qg8QkyB' 2. 해결한 명령어 (캐시 비우고 다시 설치) npm cache clean --force npm install multer multer-s3 mongoose socket.io jsonwebtoken bcrypt aws-sdk 출처 : github.com/immerjs/immer/issues/546
1. 정의 EJS는 Embedded Javascript의 약자로 많은 템플릿 엔진 중 하나이다. 템플릿과 템플릿에 보여주고 싶은 데이터가 있을때 템플릿 엔진이 이 둘을 합쳐 결과 페이지를 생성해낸다. 2. 예시 DATA : javascript / TEMPLATE : 네이버 DATA : nodejs / TEMPLATE : 네이버 3. 환경설정 1) ejs 모듈 설치 npm install ejs --save 2) app.js에 다음 소스 추가 const templateRouter = require('./router/template'); ... app.use('/template', templateRouter); 3) template.js 파일 생성이후 다음 소스 추가 var express = require("..
node.js에서 이미지 업로드를 그냥 하려고하면 확장자가 없어서 실행이 안되는 불상사가 발생한다. 그럴때 실행 가능하도록 개발하는 방법은 multer 모듈을 활용 하면 된다. 1. node.js 파일 생성 파일명 : imageUpload.js const multer = require("multer"); const storage = multer.diskStorage({ destination : (req, file, cb) => { cb(null, 'public/images/') }, filename: (req, file, cb) => { cb(null, file.originalname) } }); const upload = multer({ storage: storage }); module.exports ..
1. 모듈 설치 - 로컬 설치 : npm install module_name - 전역 설치 : npm install -g module_name 2. 모듈 삭제 - npm uninstall module_name
Q) Url 호출별 결과값 호출방법 const http = require("http"); const { resolve } = require("path"); http .createServer((req, res) => { if (req.url === "/") { res.writeHead(200); res.end("main url"); } else if (req.url === "/upload") { res.writeHead(200); res.end("upload url"); } else if (req.url === "/delete") { res.writeHead(200); res.end("delete url"); } else { res.writeHead(404); res.end("Not Found!!!"); ..
1. 서버 실행 1) 소스 입력 - 파일명 : server.js const http = require("http"); http .createServer((req, res) => { res.writeHead(200, {"Content-Type": "text/html"}); res.end("Hello Word~!!!"); }) .listen(3000, () => { console.log("3000번 포트 서버 접속 완료~!!"); }); 2) 실행 node server.js 결과 : 3000번 포트 서버 접속 완료~!! 2. 다운로드 한 Postman 프로그램 확인 ※ 인터넷에서 실행시 'localhost:3000' 입력 Postman 실행 중간에 로그인 페이지 출력시, 페이지 하단의 'Skip signin..