일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
- LifeCycle
- 자료구조
- Spring
- OOP
- REST API
- html
- dfs
- Deep Dive
- 인접행렬
- 인접리스트
- css
- 알고리즘
- java
- queue
- 코딩테스트
- 프로그래머스
- logger
- TIL
- node.js
- MySQL
- nestjs
- bean
- javascript
- 탐욕법
- winston
- 변수
- GraphQL
- Interceptor
- JWT
- typescript
- Today
- Total
목록FrameWork (54)
처음부터 차근차근
파일 리스트 읽어오기 먼저 Nodejs file list in directory를 검색해서 파일 리스트를 읽어오는 방법을 검색해보자. 굉장히 친절하게 알려준다. https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j How do you get a list of the names of all files present in a directory in Node.js? I'm trying to get a list of the names of all the files present in a directory using Node.js. I want ..
조건문과 쿼리스트링을 통하여 홈부분과 나머지 부분을 분리하였다. if queryData.id === undefined인 경우 -> 홈부분 else -> 나머지 목록 부분 var http = require('http'); var fs = require('fs'); var url = require('url'); var app = http.createServer(function(request,response){ var _url = request.url; var queryData = url.parse(_url, true).query; var pathname = url.parse(_url, true).pathname; if(pathname === '/'){ if(queryData.id === undefined){..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/2yPQF/btshRye75rB/keApjM5kqw9kKbVL56WCHk/img.png)
url.parse의 용도 Node.js에서는 URL 모듈을 통하여 URL 문자열을 객체로 바꾸거나 URL객체를 문자열로 변환하여 URL과 관련된 정보를 가져올 수 있다. 즉, URL 모듈은 URL을 통해서 입력된 값을 사용할 수 있도록 해준다. 내장모듈이라 Node.js에 포함되어 있으므로 별도의 설치가 필요 없다. URL 모듈은 parse(), format(), resolve() 총 3가지 메소드를 가지고 있다. 이 중 사용자로부터 문자열 형식으로 받은 URL 요청을 처리하기 위해 'parse()'가 가장 많이 활용된다. parse() : URL 문자열을 입력하면 URL 객체를 만든다. 'format()'의 반대 format() : URL 객체를 입력하면 URL 문자열을 반환한다. 'parse()'의 ..
Node.js 파일 다루는 방법 - 정보를 다루는 핵심적인 처리 4가지로 CURD : Create, Read, Update, Delete 이렇게 존재한다. 먼저 Node.js file read로 검색하면, 공식문서를 통해 사용법을 익힐 수 있다. var fs = require('fs'); fs.readFile('sample.txt', 'utf8', function(err, data){ console.log(data); }); https://nodejs.dev/en/learn/reading-files-with-nodejs/ Reading files with Node.js How to read files using Node.js nodejs.dev 파일을 이용한 본문 구현 - 쿼리스트링에 따라 본문이 변경되..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/kQjMV/btshPphH12m/s0SeyWTEf6bmkvPV82Tcj0/img.png)
우리의 목표 : 자바스크립트를 이용해서 Node.js가 갖고 있는 기능을 호출하여 우리가 웹 애플리케이션을 Node.js로 만들 수 있게하는 것. 이제 Node.js의 영역으로 넘어가서 웹 애플리케이션을 구현하는 아주 중요한 스킬을 알아보자. => 주인공은 url 이다. URL의 형식 1) Protocol : 통신규칙 사용자가 서버에 접속할 때 어떤 방식으로 통신할 것인가에 대한 부분. HTTP : (Hyper Text Transfer Protocol) 웹서버와 웹브라우저가 서로 데이터를 주고 받기 위해서 만든 통신 규약. 2) Host (domain) : 호스트 인터넷에 접속되어 있는 각각의 컴퓨터를 호스트라고 부른다. (opentutorials.org)는 특정 인터넷에 접속되어 있는 컴퓨터를 가리킨다..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/brnJy1/btshKQNpf55/ZNRkaMa55rTawds7JeyiFk/img.png)
1. Node.js의 등장 - 웹이 등장한 직후 여러가지 불만들이 쏟아져 나왔다. 수많은 html을 직접 타이핑해서 직접 웹페이지를 수정하는 것에 지침. 방문자들이 마음대로 글을 올리게 하고 싶었지만 그들에게 직접 html의 수정 권한을 주는 것은 위험했고 =>곧 성장의 한계에 직면하게 됐다. - 선구자들 : 귀찮고 반복적인 html 작업은 기계에게 시키자.. 컴퓨터공학자들은 이미 자바스크립트에 익숙한 웹개발자들이 새로운 언어를 배우지 않고도 웹페이지를 자동으로 생성하는 서버쪽 애플리케이션을 만들 수 있게하고 싶어했다. => Node.js 출현 - 1995년 : 넷스케이프사에서 브랜든 아이크에게 자바스크립트의 제작을 의뢰 => 자바스크립트 탄생. (웹은 사람과 상호작용하는 애플리케이션의 면모를 갖추게 됨..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cQStQo/btshyoQ1pyE/o1JXe8h2eugG2xCAh6dnq0/img.png)
app.listen도 모듈화가 가능하다. www.js 만들기 app.js 'use strict'; // express 사용해보기, 모듈 const express = require('express'); const app = express(); //라우팅 const home = require("./routes/home") // 앱 세팅 app.set("views","./views"); app.set("view engine","ejs"); app.use('/', home); // use -> 미들 웨어를 등록해주는 메서드. // app 내보내기 module.exports = app;
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/dUzSS7/btshydorZ6Q/Xcbc9eYoOGVnrdU3flNBb1/img.png)
Index.js에 있는 MVC의 컨트롤러를 분리해보자. home.ctrl.js //Controller 분리 const home = (req,res)=>{ res.render("./home/index"); } const login = (req,res) => { res.render("./home/login") } module.exports = { home, login }; index.js const express = require('express'); const router = express.Router(); //Controller 분리 후 Import const ctrl = require('./home.ctrl'); router.get('/',ctrl.home) router.get('/login',ctrl..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bflJr6/btshy6WcVdw/ISUs05ljUHDCRF31Ke7u11/img.png)
router를 분리하여 app.get을 따로 정리한다. index.js 파일 - express module의 router 메서드를 불러와서, 따로 파일을 제작했다. - 이후 module.exports 를 통해 모듈로 던지기 'use strict'; const express = require('express'); const router = express.Router(); router.get('/',(req,res)=>{ //render를 통해서 index.ejs를 불러온다. res.render("./home/index"); }) router.get('/login',(req,res)=>{ res.render("./home/login"); }) module.exports = router; app.js 파일 -..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/oAbeg/btshyLY5J7C/KIFWJleMTjnwHJxwOKA460/img.png)
app.get() 내부의 html을 정리하기 위하여 render를 사용할 것이다. 먼저 app.set을 진행한다. // 앱 세팅 app.set("views","./views"); app.set("view engine","ejs"); 이후 views폴더와 home 폴더를 제작한다. 이후 app.get 내부를 res.render 메소드를 통하여 index.ejs를 불러온다. app.get('/',(req,res)=>{ //render를 통해서 index.ejs를 불러온다. res.render("./home/index"); }) app.get('/login',(req,res)=>{ res.render("./home/login"); })