정적 페이지 const express = require('express'); const app = express(); const port = 3000; //public 디렉토리 생성 필요. //static.html(정적 파일)이 위치할 디렉토리 지정. app.use(express.static('public')); app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`); }); Hello, Static! coding coding coding coding coding 동적 페이지 const express = require('express'); const app = express(); const port ..
- Single Thread로 동작 - 비동기 처리는 Nodejs의 특징 중 하나 sync_async.js var fs = require('fs'); //Sync 동기 console.log(1); var data = fs.readFileSync('data.txt', {encoding:'utf8'}); console.log(data); //Async 비동기 console.log(2); fs.readFile('data.txt', {encoding:'utf8'}, function(err, data){ console.log(3); console.log(data); }); console.log(4); data.txt Hello Sync And Async 실행 결과 1 Hello Sync And Async 2 4 ..
1. Underscore 객체 생성 var _ = require('underscore'); 2. 배열 생성 var arr = [3,6,9,1,12]; 3. 배열 값 호출 예제 console.log(arr[0]); //배열의 첫번째 값 호출 //결과: 3 console.log(_.first(arr)); //underscore를 이용해서 배열의 첫번째 값 호출 //결과: 3 console.log(arr[arr.length - 1]); //배열의 마지막 값 호출 //결과: 12 console.log(_.last(arr)); //underscore를 이용해서 배열의 마지막 값 호출 //결과: 12 참고 www.inflearn.com/course/nodejs-%EA%B0%95%EC%A2%8C-%EC%83%9D%E..
1. cmd(터미널)에서 프로젝트 폴더로 이동 2. 프로젝트 폴더를 npm package로 지정(package.json 생성) npm init // 명령어 입력 후 환경설정 // name // version // description // entry point // test command // git respository // keywords // author // license // Is this ok? (yes) - 예제로 UnderscoreJS 설치 3. UnderscoreJS 홈페이지에서 설치법 확인 4. cmd(터미널)에 설치 명령어 입력(node_modules 폴더가 생성되고 하위에 underscore 폴더가 생성됨) npm install underscore --save * '--save' 를..
1. npm.com에서 'uglify-js' 검색 후 설치법 확인 2. cmd(터미널)에서 'npm install uglify-js -g' 또는 'npm install uglify-js' 입력 * '-g'가 붙으면 컴퓨터 전역에서 사용하는 독립적인 프로그램으로 사용, 없으면 프로젝트 내에서만 사용 3. 예제 pretty.js 코드 작성 function hello(name){ console.log('Hi,' + name); } hello('seogineer'); 4. 사용 방법 방법1 - cmd(터미널)에 pretty.js 변형 결과 바로 출력 uglifyjs pretty.js 결과1 function hello(name){console.log("Hi,"+name)}hello("seogineer"); 방법2..
Hello World 출력 1. 설치 - 폴더 생성 mkdir myapp cd myapp - package.json 생성 npm init - dependencies에 추가 npm install express --save 2. app.js 작성 const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) }) 3. cmd(터미널)에서 app.js가 위치한 폴더로 이동 4. 실..
Hello World 출력 1. 설치 과정 생략 2. webserver.js 작성 const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); 3. cmd(터미널)에서 webserver.j..
1. 파이썬 설치 - python.org에서 설치 파일 다운로드 - 설치 페이지에서 Add Python 3.xxx to PATH 체크박스를 체크 후 설치 2. 파이썬 버전 및 설치 확인 - cmd > "python -V" 입력 3. 프로젝트 폴더로 이동 - cmd에서 cd 명령을 사용해서 테스트할 프로젝트가 있는 폴더로 이동 4. 서버 구동하기 - 파이썬 버전이 3.X인 경우 : python -m http.server - 파이썬 버전이 2.X인 경우 : python -m SimpleHTTPServer - 8000 포트가 아닌 다른 포트에서 실행하려면 python -m http.server 7800과 같이 포트번호 입력 5. 서버 접속 - 웹브라우저에 "localhost:8000"을 입력하면 서버로 이동 ..
*************************** APPLICATION FAILED TO START *************************** Description: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that's listening on port 8080 or configure this application to listen on another port. 해결 방법 1. cmd(명령프롬프트) 실행 2. netstat -ano 입력 3. PID 확인 4. taskkill /pid PID /f 입력 예) taskkill /pid 1036 /f
증상 서버에서 파일을 읽어오다가 실패하면서 console에 "net::ERR_CONTENT_LENGTH_MISMATCH 200" 출력 원인 서버에서 읽어오는 파일의 크기와 Header에 설정된 파일의 Content-Length의 크기가 달라서 발생 해결 upload 할 때 파일 크기를 추출해서 DB에 저장한다. @PostMapping("/uri") public String upload(@RequestParam("file") MultipartFile file) { Object obj = new Object(); obj.setFileSize((int) file.getSize());//MultipartFile의 getSize() 메소드로 파일 크기를 추출한다. service.insert(obj);//추출한 파..