Node.js: Difference between revisions
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
== Installation == | == Installation == | ||
<pre> | <pre> | ||
$ sudo apt-get install nodejs-legacy | $ sudo apt-get install nodejs-legacy | ||
Line 17: | Line 16: | ||
Try: sudo apt-get install <selected package> | Try: sudo apt-get install <selected package> | ||
</pre> | </pre> | ||
7.x 버전대의 nodejs 설치. | |||
<source lang=bash> | |||
$ curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - | |||
$ sudo apt-get install -y nodejs | |||
</source> | |||
보통은 패키지로 설치해도 되지만, 최신의 node.js 를 사용하기 위해서는 별도의 업데이트를 해야한다. | |||
<source lang=bash> | |||
$ sudo npm cache clean -f | |||
$ sudo npm install -g n | |||
$ sudo n stable | |||
$ sudo ln -sf /usr/local/n/versions/node/<node-version>/bin/node /usr/bin/node | |||
</source> | |||
== Install packages == | == Install packages == | ||
Line 71: | Line 87: | ||
* http://nodeguide.com/ - Felix's Node.js Guide | * http://nodeguide.com/ - Felix's Node.js Guide | ||
* https://scotch.io/books/build-your-first-node-js-app - Build Your First Node.js App | * https://scotch.io/books/build-your-first-node-js-app - Build Your First Node.js App | ||
* https://www.codementor.io/codeforgeek/build-website-from-scratch-using-expressjs-and-bootstrap-du107sby7 - build-website-from-scratch-using-expressjs-and-bootstrap | |||
* https://zellwk.com/blog/crud-express-mongodb/ - Building a Simple CRUD Application with Express and MongoDB | |||
* https://zellwk.com/blog/crud-express-and-mongodb-2/ - Building a Simple CRUD Application with Express and MongoDB – Part 2 | |||
== References == | == References == |
Latest revision as of 19:49, 26 January 2018
Overview
Node.js 정보 정리
Installation
$ sudo apt-get install nodejs-legacy $ sudo apt-get install npm
Ubuntu 에서 node.js 설치시, 설치가능한 패키지가 두개가 있다. 보통은 nodejs-legacy 를 설치하면 된다<ref>http://stackoverflow.com/questions/20057790/what-are-the-differences-between-node-js-and-node</ref>.
$ node -v The program 'node' can be found in the following packages: * node * nodejs-legacy Try: sudo apt-get install <selected package>
7.x 버전대의 nodejs 설치. <source lang=bash> $ curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - $ sudo apt-get install -y nodejs </source>
보통은 패키지로 설치해도 되지만, 최신의 node.js 를 사용하기 위해서는 별도의 업데이트를 해야한다. <source lang=bash> $ sudo npm cache clean -f
$ sudo npm install -g n
$ sudo n stable
$ sudo ln -sf /usr/local/n/versions/node/<node-version>/bin/node /usr/bin/node </source>
Install packages
node.js 에서 사용하는 패키지를 설치하기 위해서는 npm 명령어를 사용하면 된다.
예를 들어, 아래 hello world 예제에서 사용하는 express 패키지를 설치하기 위해서는 다음을 입력하면 된다.
$ sudo npm install express
-g
-g 옵션은, 패키지 설치시, global 로 설치한다는 뜻이다.
$ npm install -g nodemon
--save
... need info
Hello world
<source lang=javascript> var express = require('express'); var app = express();
app.get('/', function(req, res){
res.send('Hello world!');
})
var server = app.listen(3000, function() {
var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port);
}); </source>
다음과 같이 실행한다.
$ node app.js
다음과 같이 테스트하면 된다.
$ curl localhost:3000 Hello world!
See also
- http://www.nextree.co.kr/p8574/ - Node.js: Hello로 시작하는 Web 애플리케이션
- https://nodejs.org/api/http.html - Node.js Manual & Documentation
- http://nodeschool.io/#workshoppers - nodeschool workshoppers
- http://book.mixu.net/node/ - Mixu's Node book
- http://nodeguide.com/ - Felix's Node.js Guide
- https://scotch.io/books/build-your-first-node-js-app - Build Your First Node.js App
- https://www.codementor.io/codeforgeek/build-website-from-scratch-using-expressjs-and-bootstrap-du107sby7 - build-website-from-scratch-using-expressjs-and-bootstrap
- https://zellwk.com/blog/crud-express-mongodb/ - Building a Simple CRUD Application with Express and MongoDB
- https://zellwk.com/blog/crud-express-and-mongodb-2/ - Building a Simple CRUD Application with Express and MongoDB – Part 2
References
<references />