Node.js Tutorial for Beginners


1. What is Node

  • Great for prototyping and agile development
  • Superfast and highly scalable
  • Javascript everywhere
  • Cleaner and more consistent codebase
  • Large ecosystem of open-source libs
  • 2. Node Architecture


    it's a runtime environment for executing javascript code.

    3. How Node Works


  • non-blocking or asynchronous

  • blocking or synchronous
  • Node applications are asynchronous by default.
    Node is ideal for I/O-intensive apps.
    Do not use Node for CPU-intensive apps.

    4. Installing Node


    Node.js Download

    5. Your First Node Program

    function sayHello(name) {
    console.log('Hello '+name);
    }
    
    sayHello('Karam');
    [実行結果]node app.js
    Hello Karam

    6. Node Module System

  • os(operating system)
  • fs(file system)
  • events
  • http
  • 7. Global Object

    // global.변수명
    
    global.setTimeout()
    global.clearTimeout();
    global.setInterval();
    global.clearInterval();

    8. Modules

    // app.js
    
    console.log(module);
    [実行結果]node app.js
    Module {
      id: '.',
      path: 'C:\\workspace\\first-app',
      exports: {},
      parent: null,
      filename: 'C:\\workspace\\first-app\\app.js',
      loaded: false,
      children: [],
      paths: [
        'C:\\workspace\\first-app\\node_modules',
        'C:\\workspace\\node_modules',
        'C:\\node_modules'
      ]
    }

    9.Creating a Module

    // logger.js
    
    var url = 'http://mylogger.io.log';
    
    function log(message){
        // Send an HTTP request
        console.log('hello, log message is ' + message);
    }
    
    module.exports.log = log;

    10. Loading a Module

    //app.js
    
    var logger = require('./logger');
    
    console.log(logger);
    logger.log('message');
    [実行結果]node app.js
    { log: [Function: log] }
    hello, log message is message
    export a single function or an object
    // logger.js
    var url = 'http://mylogger.io.log';
    
    function log(message){
        // Send an HTTP request
        console.log('hello, log message is ' + message);
    }
    
    module.exports = log;
    
    // app.js
    
    const log = require('./logger'); // var가 아닌 const를 사용하는 이유: 변수의 재할당을 막기 위해서
    
    log('message');
    
    [実行結果]node app.js
    hello, log message is message
    更新

    11. Module Wrapper Function


    12. Path Module


    13. OS Module


    14. File System Module


    15. Events Module


    16. Event Arguments


    17. Extending EventEmitter


    18. HTTP Module


    注意事項


    Node.js Tutorial for Beginners: Learn Node in 1 Hour