NodeJS

  • Unlike a browser environment, every node module gets its own private scope
  • Using the import VARIABLE from 'A_NODE_MODULE'; syntax, the default object of the A_NODE_MODULE is exported

Express

  • Express is a wrapper around NodeJS HTTP and HTTPS core modules
  • Although the core modules are very powerful, more complex requests would involve writing lots of boilerplate code. Express is used to circumvent this and replace a lot of boilerplate with magic

Directory Structure

  • src directory contains all JavaScript frontend modular code
  • public directory contains all static frontend assets like CSS, HTML and JavaScript
  • api directory contains all files related to the backend API server

Imports

  • import "./something" will automatically look for something.js, so there is no need to include the file extension in the import parament
  • Multiple import statements will import from the cache after the first successful import so it's OK to import the same value multiple times
  • Variables defined in an imported module are not automatically available in the importing module (i.e. these variables are not on a global scope)
    • NodeJS therefore automatically scopes variables in modules without the need for an IIFE

Exports

  • The destructure syntax is used to import non-default exports. Constants and functions can then be invoked as if they were available locally