Microsoft Windows [Version 10.0.16299.248]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\goo30>node -v
v8.9.4
C:\Users\goo30>node
> 1+1
2
> console.log(1+1)
2
undefined
>
(To exit, press ^C again or type .exit)
>
C:\Users\goo30>dir
C 드라이브의 볼륨: Windows
볼륨 일련 번호: C8EB-534C
C:\Users\goo30 디렉터리
2018-02-21 오후 01:26 <DIR> .
2018-02-21 오후 01:26 <DIR> ..
2018-01-30 오후 04:33 <DIR> .android
2018-02-06 오전 11:29 <DIR> .idlerc
2018-01-30 오후 04:32 <DIR> .IntelliJIdea2017.3
2018-01-30 오후 05:22 <DIR> .m2
2018-02-21 오후 01:33 51 .node_repl_history
2018-02-20 오후 05:45 <DIR> 3D Objects
2018-02-09 오전 10:18 <DIR> brackets_nodejs
2018-02-20 오후 05:45 <DIR> Contacts
2018-02-20 오후 05:45 <DIR> Desktop
2018-02-20 오후 05:45 <DIR> Documents
2018-02-20 오후 05:45 <DIR> Downloads
2018-02-09 오전 10:08 <DIR> Dropbox
2018-02-20 오후 05:45 <DIR> Favorites
2018-02-20 오후 05:45 <DIR> Links
2018-02-20 오후 05:45 <DIR> Music
2018-02-21 오후 01:31 <DIR> OneDrive
2018-01-30 오후 04:27 <DIR> Oracle
2018-02-20 오후 05:45 <DIR> Pictures
2018-02-20 오후 05:45 <DIR> Saved Games
2018-02-20 오후 05:45 <DIR> Searches
2018-02-20 오후 05:45 <DIR> Videos
2018-02-12 오후 10:02 501,591 익스포트.sql
2개 파일 501,642 바이트
22개 디렉터리 399,721,988,096 바이트 남음
C:\Users\goo30>d:
D:\>cd workspaceNode
D:\workspaceNode>mkdir testbts
D:\workspaceNode>cd testbts
D:\workspaceNode\testbts>mkdir frontend
D:\workspaceNode\testbts>mkdir backend
D:\workspaceNode\testbts>cd backend
D:\workspaceNode\testbts\backend>npm install express-generator --save
npm WARN saveError ENOENT: no such file or directory, open 'D:\workspaceNode\testbts\backend\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'D:\workspaceNode\testbts\backend\package.json'
npm WARN backend No description
npm WARN backend No repository field.
npm WARN backend No README data
npm WARN backend No license field.
+ express-generator@4.15.5
added 6 packages in 2.114s
D:\workspaceNode\testbts\backend>npm install express-generator -g
C:\Users\goo30\AppData\Roaming\npm\express -> C:\Users\goo30\AppData\Roaming\npm\node_modules\express-generator\bin\express-cli.js
+ express-generator@4.15.5
added 6 packages in 1.024s
D:\workspaceNode\testbts\backend>
보기에서 숨김파일체크하면 C:\Users\goo30\AppData\Roaming\npm\node_modules
파일이 생성된걸 확인할 수 있다.
D:\workspaceNode\testbts\backend>cd..
D:\workspaceNode\testbts>express --view=jade backend
//익스프레스를 만드는데 백엔드 디렉토리에 만든다.기본뷰는 jade형태로 만든다.
destination is not empty, continue? [y/N] y
create : backend
create : backend/package.json
create : backend/app.js
create : backend/public
create : backend/views
create : backend/views/index.jade
create : backend/views/layout.jade
create : backend/views/error.jade
create : backend/routes
create : backend/routes/index.js
create : backend/routes/users.js
create : backend/bin
create : backend/bin/www
create : backend/public/stylesheets
create : backend/public/stylesheets/style.css
install dependencies:
> cd backend && npm install
run the app:
> SET DEBUG=backend:* & npm start
create : backend/public/images
create : backend/public/javascripts
D:\workspaceNode\testbts>cd backend
D:\workspaceNode\testbts\backend>npm install
//이클립스에서 메이븐 라이브러리 다운받듯이 다운로드를 시작한다.
npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated constantinople@3.0.2: Please update to at least constantinople 3.1.1
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
added 102 packages and removed 4 packages in 7.969s
> backend@0.0.0 start D:\workspaceNode\testbts\backend
> node ./bin/www "DEBUG=backend:*"
//ctrl+c를 누르면 stop
//일괄 작업을 끝내시겠습니까 (Y/N)? y
//브라우저에서 http://localhost:3000/ 로 접속하면
GET / 200 473.942 ms - 170
GET /stylesheets/style.css 200 3.967 ms - 111
GET /favicon.ico 404 16.571 ms - 1135 //favicon 설치를 안해서 뜨는거니 상관없음
ctrl+c로 종료하고
일괄 작업을 끝내시겠습니까 (Y/N)? y
D:\workspaceNode\testbts\backend>npm start DEBUG=backend:*
> backend@0.0.0 start D:\workspaceNode\testbts\backend
> node ./bin/www "DEBUG=backend:*"
http://localhost:3000/api/movies 접속하면
GET /api/movies 200 5.343 ms - 922
GET /api/movies 200 1.157 ms - 922
GET /favicon.ico 404 467.369 ms - 1135
http://localhost:3000/api/movies/1 접속하면
GET /api/movies/1 200 2.072 ms - 143
console.log(movies) 로 출력하고 재시작하면
일괄 작업을 끝내시겠습니까 (Y/N)? y
D:\workspaceNode\testbts\backend>npm start DEBUG=backend:*
> backend@0.0.0 start D:\workspaceNode\testbts\backend
> node ./bin/www "DEBUG=backend:*"
[ { id: 1,
name: '공조',
year: 2017,
director: '김성훈',
poster: 'http://img.cgv.co.kr/Movie/Thumbnail/Poster/000079/79416/79416_185.jpg' },
{ id: 2,
name: '컨택트',
year: 2017,
director: '드니 빌뇌브',
poster: 'http://img.cgv.co.kr/Movie/Thumbnail/Poster/000079/79437/79437_185.jpg' },
{ id: 3,
name: '더킹',
year: 2017,
director: '한재림',
poster: 'http://img.cgv.co.kr/Movie/Thumbnail/Poster/000079/79423/79423_185.jpg' },
{ id: 4,
name: '모아나',
year: 2017,
director: '론 클레멘츠, 존 머스커',
poster: 'http://img.cgv.co.kr/Movie/Thumbnail/Poster/000079/79316/79316_185.jpg' },
{ id: 5,
name: '라이언',
year: 2017,
director: '가스 데이비스',
poster: 'http://img.cgv.co.kr/Movie/Thumbnail/Poster/000079/79396/79396_185.jpg' },
{ id: 6,
name: '너의 이름은',
year: 2017,
director: '신카이 마코토',
poster: 'http://img.cgv.co.kr/Movie/Thumbnail/Poster/000079/79313/79313_1000.jpg' } ]
GET /api/movies 304 18.405 ms - -
재시작하지않으면 반영이 안됨
http://localhost:3000/api/movies/1
에서 1은 자동으로 id라고 인식함 소스에서 /:id 이부분임
router.get('/:id', function (req, res, next) {
var id = parseInt(req.params.id, 10)
var movie = movies.filter(function (movie) {
return movie.id === id
});
res.send(movie)
});
'개발하자 > node.js' 카테고리의 다른 글
helloWorld 출력하기 (0) | 2015.09.01 |
---|