Skip to content

Learn and understand NodeJS

课程地址

Notes

  • Microprocessor(a tiny machine) -> which accept instructions(IA-32 X86-64 ARM MIPS)-> which accept different Machine Code/Language(programming languages spoken by computer processors)-> Assembly Language -> C/C++ -> Javascript
  • Node itself is written in C++, cause V8 (the thing that compiles js into machine code) is written in C++
  • ECMASCRIPT is the standard (that how the language should work) js is based on since there're many engines, and V8 is just one of many js engines. 所以如果你要写 js 引擎,就要参考 ecma 规则啦!
  • A javascript engine: A program that converts js code into something the computer processor can understand. And it should follow the ECMAScript standard on how the language should work and what features it should have.
  • V8: 提供了被 embedded 到其他 C++ 程序里的功能,并且有一些 hook。所以你甚至可以直接给 js 加语法 feature!
  • node is basically a library and a framework of code
  • Every file written in node is wrapped in a wrapper function, so code can reference' module' and 'require' and these node variables and so on.

image-20220915161321992

And then node exexutes this function

  • JSON: Javascrpt object notation — A standard that is inspired by js object literals
  • Events: System Event(c++ core libuv) => Custom Events(Event emitter)
  • Class: Syntax sugar
  • Node 的 Async 在于 v8 里的 js 代码可以和 libuv 里的 io 操作同步执行

image-20220915161341013

  • Buffer: A temporary holding spot for data being moved // intetntionally limited in size -> gather some data and move alone

  • Streams: A sequence of data made available over time(边看电影边缓冲)

  • Character Set: A Representation of characters as numbers.

  • Character Encoding: how many bits to store character set(the number of the character, e.g. Unicode) and the rule to store them. (区分 character set 与 character encoding)


  var buffer = new ArrayBuffer(8);
  var view = new Int32Array(buffer); //es6 typed array

  view[0]=5; view[1]=15;

  view[2]=10 //doesnt work, 'cause int32 means 32bit (4Byte) an array item, and buffer 8 means 8 Byte (or 64 bits), so only two items in Int32Array.

  • 关于 sync 与 asnyc 如果一个用户请求用 sync,如果多个用户请求(即同时执行多个node 文件)用 aysnc
  • serialize: translate an object into a format that can be stored or transferred. like JSON, CSV, XML.. // 记住专业术语哦
  • Routing: mapping http requests to content
  • The largest ecosystem of open code in history - npm
  • 从传统的 relational database 到 document database: 硬件的存储成本降低了 数据更新的频率和速度要求提高了
  • 再次强调,DOM 实际上是归属于浏览器下层的东西!只是可以被 js -> c++ 控制罢了(所以这部分功能也是 js engine 给 js 附加的)