본문 바로가기

Web/Node.js15

Node.js move file 파일 이동 var fs = require('fs'); fs.rename(oldpath, newpath, callback); 2017. 7. 11.
Node.js String.replace 문자열 변경 var variableString = 'temp/aaa.jpg'; variableString = variableString.replace('temp', 'image'); console.log(variableString); image/aaa.jpg 파일 위치 변경 로직을 만들다보니 문자열을 변경해야하는 상황이 발생했다.방법은 자바와 같았는데 왜 이렇게 헤맸는지... 2017. 7. 11.
Node.js multiparty 이용해 File upload - ajax 이 포스팅은 Windows 32bit 환경에서 진행하였으며 Node.js가 설치되어 있어야 합니다. Node.js 설치 방법은 아래 포스트에서 확인하실 수 있습니다. Window 환경에서 Node.js 설치 및 Hello world 출력하기 0. 만들려 하는 것 예를들어 글쓰기를 하는데 이미지 업로드가 필요한 경우, 파일을 업로드 하려면 form 태그 안에 넣어야 하는데 form 태그 안에 form 태그가 들어갈 수 없으므로 ajax를 통해 이미지를 미리 업로드하려고 했습니다. 따라서 파일을 선택하면 그 파일을 미리 서버에 저장하고 그 파일의 경로 및 이름을 return 받는 모듈을 만들 것입니다. 1. express project 생성 (1) express-generator 설치 express 프로젝트.. 2017. 7. 9.
Mongoose로 Node.js와 연결 시 DeprecationWarning // mongodb setup var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/mydb'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function() { // we're connected! console.log('connected successfully'); }); 다음과 같은 Warning이 발생함(node:1876) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri().. 2017. 7. 6.