Node.js: Difference between revisions

From 탱이의 잡동사니
Jump to navigation Jump to search
No edit summary
Line 72: Line 72:
* 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://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 ==

Revision as of 22:06, 6 January 2018

Overview

Node.js 정보 정리

Installation

Ubuntu

$ 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>

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

References

<references />