Skip to content

Node Ecosystem

all1124 edited this page Sep 28, 2019 · 2 revisions

Readings: Node Ecosystem

The Module Wrapper

https://nodejs.org/docs/latest/api/modules.html#modules_the_module_wrapper

  • Node.js wraps a modules code in a function wrapper before it is executed

     (function(exports, require, module, __filename, __dirname) {
     // Module code actually lives in here
     });
    
  • Keeps top-level variables scoped to the module rather than the global object

  • It helps to provide some global-looking variables that are actually specific to the module, such as:

    • The module and exports objects that the implementor can use to export values from the module
    • The convenience variables __filename and __dirname, containing the module's absolute filename and directory path

Test Driven Development (TDD)

https://jrsinclair.com/articles/2016/gentle-introduction-to-javascript-tdd-intro/

Why?

  1. It forces one to think
    • What are you trying to achieve?
  2. It makes debugging easier
  3. It makes coding more fun

What is TDD?

  • Where you write tests before you write application code
  • Steps to TDD:
    • Red: Write a test and make sure it fails
    • Green: Write the simplest, easiest possible code to make the test pass
    • Refactor: Optimize and/or simplify the application code, making sure that all the tests still pass
    • Once you finish step 3, you start the cycle again by writing another test
  • Writing tests
    • Write the simplest test possible first
    • Tests are written in the form: Describe [thing]. It should [do something]
    • Checking: expect(actualValue).to.equal.(expectedValue)
      • Use equal when comparing numbers, strings, or booleans, and use eql when comparing arrays or objects
    • No module code until there’s a failing test
    • When your tests pass, refactor your code

Building a JavaScript and Node.js project

https://docs.travis-ci.com/user/languages/javascript-with-nodejs

  • The easiest way to specify Node.js versions is to use one or more of the latest releases in your .travis.yml

  • Optionally, your repository can contain a .nvmrc file in the repository root to specify which single version of Node.js to run your tests against

  • The default build script for projects using nodejs is:

    • npm test
  • Travis CI uses npm or yarn to install your project dependencies

    Note that there are no npm packages installed by default in the Travis CI environment

V8

https://v8.dev/

  • V8 is Google’s open source high-performance JavaScript and WebAssembly engine

Guide to ES6

https://medium.com/sons-of-javascript/javascript-an-introduction-to-es6-1819d0d89a0f#.wb7rj1gin

  • Arrow functions and let keyword; Block scopes
  • Classes and inheritance; Default parameters
  • Destructured assignment
  • Generators; Iterators; Maps
  • Promises; Rest parameters; Sets
  • Spread operator; Template Literals

ECMAScript 2015 (ES6) and beyond

https://nodejs.org/en/docs/es6/

  • All ES6 features are split into three groups for shipping, staged, and in progress features

npm-package.json

https://docs.npmjs.com/files/package.json.html

  • All you need to know about what’s required in your package.json file

How to Use npm as a Build Tool

https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/

npm-scripts

https://docs.npmjs.com/misc/scripts

Videos:

TDD:

http://www.letscodejavascript.com/

NPM:

https://docs.npmjs.com/about-npm/index.html

Additional resources:

ES6 Features:

http://es6-features.org/#ClassInheritance

NPM docs:

https://docs.npmjs.com/

Clone this wiki locally