Intro to Node.js

2019-04-02



What can I create with Nodejs?


Installing Node


Running Nodejs code

REPL for playing around, CLI for everything else!


node가 여러개 설치 된 경우 (nvm, brew등으로 인해) 어떤 노드를 쓰고 있는지 확인 하고 싶을때 $ which node

bash_profile

bashrc


Browser and Nodejs

Browser

Nodejs


Globals


modules in Nodejs

Creating modules

Importing modules

// lib.js
module.export = () => {
  console.log('hello i am library')
}
// app.js
const someModule = require('./lib')

Internal Modules

const fs = require('fs')
const file = fs.readFileSync('./lib.js', {encoding: 'utf-8'}).toString()

fs.writeFileSync('./lib.js', 'var me="me"')

Async Code

Async patterns


Error handling


Debugging

  1. console.log
  2. use node inspector node —inspect <file> go to chrome://inspect

Testing

Types of Test