티스토리 뷰

https://github.com/ddulhddul/nodejsTutorials/

https://opentutorials.org/course/2136


# NodeJs Tutorials


## Orientation : 서버 측 자바스크립트와 nodejs소개

    WebBrowser vs nodejs

    nodejs 의 경쟁자 : ruby python java

    장점 ? 속도

        event driven programming

        non blocking IO


## Nodejs 설치 및 실행

    http://nodejs.org/

    node --version

    D:\dev\js\server_side_javascript 폴더생성

    node hello.js : 실행명령


## 간단한 웹 애플리케이션 만들기

    webserver.js

    인터넷의 동작 방법?


## 모듈과 NPM

    const : 상수

    module.js


    NPM ? Node package manager

     >> 타인의 모듈을 사용하는 방법

     >> 설치 삭제 업그레이드 의존성관리

     >> https://www.npmjs.com/

    

    Example)

    npm install uglify-js -g

    -g ? 컴퓨터 전역에서 사용

    $ uglifyjs pretty.js

        function hello(name){console.log("Hi, "+name)}hello("ddulh");

    $ uglifyjs pretty.js -m

        function hello(l){console.log("Hi, "+l)}hello("ddulh");

    $ uglifyjs pretty.js -o pretty.min.js -m

     >> 공백이나 이런것들을 제거...


    npm init

    npm install underscore --save

    underscore.js


## 콜백함수

    > a.sort(function(a,b){return b-a;})

        [ 3, 2, 1 ]


## 동기와 비동기 프로그래밍

    sync_async.js


## Express-도입

    http://expressjs.com/


## Express-설치

    $ npm install express --save


## Express-간단한 웹애플리케이션 만들기

    app.js

    app.get : 라우터 // 사용자와 controller 를 연결


## 연결성

    Nodejs // FS, HTTP, OS

    


## Express-정적파일을 서비스하는 법

    app.use(express.static('public')); //directory 이름


## Express-웹페이지를 표현하는 방법

    /dynamic    //서버재시작 필요

    static.html

        >> 두가지의 장점을 결합 > 템플릿 엔진


## Express-템플릿 엔진 (Jade)

    $ npm install jade --save

    app.set('view engine', 'jade');

    app.set('views', './views');    //default

    temp.jade

    https://www.npmjs.com/package/jade


## Express-URL을 이용한 정보의 전달

    query string ? http://localhost/topic?id=1

    시멘틱 url ?

        http://localhost/topic/1

        /topic/:id

            //req.query.id 

            //req.params.id - 시멘틱

        /topic/:id/:mode


## Express-POST 방식을 이용한 정보의 전달

    get vs post

    form.jade

    app.post('/form_receiver', function (req,res)

    >> post 읽으려면

    $ npm install body-parser --save

        var bodyParser = require('body-parser');

        app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded


## 팁 - Nodejs를 자동으로 재시작

    https://www.npmjs.com/package/supervisor

    $ npm install supervisor -g


## 웹에플리케이션 제작

    app_file.js

    view.jade

    new.jade


## 파일 업로드

    multer

    https://github.com/expressjs/multer

    $ npm install multer --save

    app.use('/user', express.static('uploads'));

    app.post('/upload', upload.single('userfile'), function (req,res) {


## 데이터베이스


## Orientdb 소개 및 기본 사용법

    http://orientdb.com/orientdb/

        Graph Database

        Document Database   

        Object-Oriented Concepts

        User and Role Security // 행 단위

        Multi-Master Replication

    http://orientdb.com/docs/last/Tutorial-Installation.html

    기본적으로 java 필요

    /d/dev/orientdb-community-2.2.15/bin

        > ./server.bat

        > root pw : 1q2w3e4r

    http://localhost:2480


    npm install oriento --save

    database_orientdb.js


## Orientdb로 웹에플리케이션 구현


## cookie1

    session 인증

    npm install cookie-parser --save


## cookie2

    shopping cart


## cookie 암호화?

    http -> https

    cookies -> signedCookies


## session 1,2

    npm install express-session --save

    npm install session-file-store --save


## session 3

    npm install session-file-store --save

    var mySqlStore = require('express-mysql-session')(session)


## Multi User(다중사용자)


## Security -password (비밀번호 보안)

    $ npm install md5

    var md5 = require('md5')

    $ npm install sha256

    $ npm install sha512

    $ npm install pbkdf2-password --save

    var bkfd2Password = require('pbkdf2-password')

    var hasher = bkfd2Password();

    var assert = require("assert");

    var opts = {

      password: "helloworld"

    };

     

    hasher(opts, function(err, pass, salt, hash) {

        if(hash == user.password){

            req.session.displayName == user.displayName;

            req.session.save(function(){

                res.redirect('/welcome')

            })

        }else{

            res.send('nonono')

        }

    });


## passportJS

    읹으을 쉽게 구현할 수 있도록 고안된 모듈

    Federation Authentification (타사 인증 like google)

    app_passport.js

    $ npm install passport --save

    $ npm install passport-local --save

    

'Programming > Javascript' 카테고리의 다른 글

[React.js] 튜토리얼  (583) 2017.03.02
[react] reactJs 튜토리얼  (580) 2017.03.01
[nodejs] crawling test  (941) 2017.02.13
[IE] frame 속 frame 디버깅   (1029) 2016.04.04
[jqxGrid] 그리드 행을 가져올때 유의해야될 사항  (917) 2015.06.22
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
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
글 보관함