Server-side Javascript (Node)

Introduction to the Node Server Side Javascript Runtime

  • NodeJS Documentation
  • Freecodecamp explanation
  • This is the runtime engine that our npm packages run on
  • It is non blocking which makes it really fast
  • Chrome's v8 engine also increases performance
  • Node gives you a runtime environment within which you can build applications.
  • type node into the terminal to check it out

Javascript Review

Topics

  • Functions
    • traditional syntax
    • fat arrow
    • passing arguments
    • mdn doc
    • Tip Create small focused functions that do a single job well
  • Conditionals
    • excellent for error handling

Arrays

  • Try to avoid using mutable array methods. instead make use of immutable array methods. These will work with the original data, but not change it. Allowing you to reuse it many times over -read this article

Higher Order Functions

If regular for loops are easy and you want more, explore the following higher order functions that are great at working with arrays

1. Node Global Objects

Materials

Activities


2. Builtin modules

  • path module

Terminology

Node Builtin Module : Modules that are included with the Node runtime environment. These modules need to be imported into your script but do not need to be installed with npm.

Materials

Key Takeaways

  • Although builtin modules come pre-installed with Node, they still need to be imported into your script with require().

Activities

  • Using the path builtin module and the __filename constant, create a node app that prints the file name (without directory) and extension of the current script.
  • Using path.isAbsolute, determine if the first two arguments of process.argv are absolute paths or not.

3. fs module

Materials

Key Takeaways

  1. Read files asynchronously whenever possible.
  2. The "dot-slash" characters ./ at the beginning of a path mean it's location is relative to the current script.
  3. fs.readFile() and fs.readdir() use "error-first callbacks" where the first argument passed to a callback is the error, if there was one. This is a common pattern in Node.

4. Lab Time

  • Can any of the following sample code be refactored to take arguments from the command line?

Miscellaneous Node-friendly Gists


Prep