Skip to content

Latest commit

ย 

History

History
175 lines (77 loc) ยท 3.06 KB

Nodejs.md

File metadata and controls

175 lines (77 loc) ยท 3.06 KB

Node.js

  • ์ƒํ™œ์ฝ”๋”ฉ์œผ๋กœ ๊ณต๋ถ€ํ•œ๊ฑฐ ์ •๋ฆฌํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. OSํ™˜๊ฒฝ์— ๋”ฐ๋ฅธ ์„ค์น˜๋Š” ์ข‹์€ ๋ธ”๋กœ๊ทธ๋“ค์ด ๋งŽ์•„์„œ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค. ์ €๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ง„ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

    curl https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
    ์‰˜ ์žฌ์‹คํ–‰
    nvm install stable
  • ํ„ฐ๋ฏธ๋„์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ช…๋ น์–ด

    1. ํŒŒ์ผ ์‹คํ–‰
    node main.js  // ์‹คํ–‰ํ•˜๊ณ ์ž ํ•˜๋Š” ํŒŒ์ผ์ด main.js์ธ ๊ฒฝ์šฐ
    nodemon main.js. // ์ˆ˜์ •์ด ์žˆ์œผ๋ฉด ์ž๋™์ ์œผ๋กœ ์„œ๋ฒ„ ์žฌ์‹คํ–‰ ํ•ด์ฃผ๋Š” ํˆด
  
  

 



## ๋ฌธ๋ฒ•

### 1. Template literal ` (๊ทธ๋ ˆ์ด๋ธŒ ์—‘์„ผํŠธ)

<img width="306" alt="์Šคํฌ๋ฆฐ์ƒท 2020-02-01 ์˜คํ›„ 8 46 39" src="https://user-images.githubusercontent.com/42775225/73591606-fbe5a000-4533-11ea-8e47-52f84a823643.png">

 : esc ๋ฐ‘์— ์žˆ๋Š” `๋กœ string์„ ๊ฐ์‹ธ๋ฉด, 

1. ๋ณ€์ˆ˜๋ฅผ ${}๋กœ ๊ฐ์‹ธ์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. 
2. '\n' ๋Œ€์‹  ์—”ํ„ฐ๋ฅผ ์น˜๋ฉด ๋œ๋‹ค.
3. html์ฝ”๋“œ๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

```javascript
var name = 'oh';
var str = `My name is ${name}`;

2. URL

์Šคํฌ๋ฆฐ์ƒท 2020-02-01 ์˜คํ›„ 9 13 43

3. File System

1) fs.readFile(path[, options], callback)

[ํด๋” ๊ตฌ์กฐ]

์Šคํฌ๋ฆฐ์ƒท 2020-02-01 ์˜คํ›„ 10 00 34

main.js
var fs = require('fs');
fs.readFile('sample.txt', 'utf8', (err, data) => {
  console.log(data);
})

4. ์—ฐ์‚ฐ์ž

== : Equal Operator

์˜ˆ) a==b ์˜ ๊ฒฝ์šฐ๋Š” a์™€ b์˜ '๊ฐ’'์ด ๊ฐ™์€์ง€๋ฅผ ํŒ๋‹จํ•œ๋‹ค.

=== : Strict Equal Operator

์˜ˆ) a===b ์˜ ๊ฒฝ์šฐ๋Š” a์™€ b์˜ '๊ฐ’'๊ณผ 'ํƒ€์ž…'์ด ์ •ํ™•ํ•˜๊ฒŒ ๊ฐ™์€์ง€๋ฅผ ํŒ๋‹จํ•œ๋‹ค.

ps) ๋˜๋„๋ก์ด๋ฉด ๋น„๊ต ์—ฐ์‚ฐ์ž๋Š” === ๋ฅผ ์‚ฌ์šฉํ•ฉ์‹œ๋‹ค.

[ ์ „์ฒด์ฝ”๋“œ ]

var http = require('http');
var fs = require('fs');
var url = require('url');

app.createServer(function(req, res){
  var _url = req.url;
  var queryData = url.parse(_url, true).query; // url๋ชจ๋“ˆ์˜ parse๋ฉ”์„œ๋“œ๋กœ return๊ฐ’์€ query string
  if(_url == '/'){
    _url = '/index.html';
  }
  if(_url == '/favicon.ico'){
    return res.writeHead(404);
  }
  res.writeHead(200);
  res.end(fs.readFileSync(__dirname+_url)); 
  // end๋ฉ”์„œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ html์ฝ”๋“œ๋ฅผ ๋‹ด์€ ๋ณ€์ˆ˜๋ฅผ ์ค˜๋„ ๋œ๋‹ค. ์ง€๊ธˆ์€ ์‚ฌ์šฉ์ž๊ฐ€ ์ ‘์†ํ•œ url์— ๋”ฐ๋ผ์„œ ํŒŒ์ผ์„ ์ฝ๊ณ  ์žˆ๋‹ค.
  
})
app.listen(3000)  // 3000ํฌํŠธ ๋Œ€๊ธฐ ์ค‘

passport

passport-local : id, pw๋กœ ์ ‘์†ํ•˜๋Š” ๋ฐฉ๋ฒ•

passport-๋ญ์‹œ๊ธฐ : facebook์œผ๋กœ ์ ‘์†ํ•˜๋Š” ๋ฐฉ๋ฒ•

tar -xvf tarํŒŒ์ผ

wget http://// ~~tar

npm install => node_modules ๊ฐ€ ์ƒ๊ธด๋‹ค. ์™ธ๋ถ€๋ชจ๋“ˆ

go build ํ–ˆ์„ ๋•Œ, ํŒจํ‚ค์ง€ ๋ชป ์ฐพ๋Š”๋‹ค๊ณ  ํ•˜๋ฉด,

echo $GOPATH

cd github.com/hyperledger/fabric ๊ฐ€์„œ

git branch ํ•ด๋ณด๊ณ 

git checkout tags/v1.4.4

go get -u ""

vim์—์„œ

%s/์ฐพ์„์–ธ์–ด/๋ฐ”๊ฟ€์–ธ์–ด