Node.js Fundamentals

As a non-blocking programming language with amazing concurrency capabilities, it is no surprise that JavaScript shines just as brightly on the server side as it does in a browser. Whether you are making a build tool, web application or API, the rich JavaScript ecosystem and Node core libraries are by your side.

Node.js Fundamentals

Not a browser

You already know how to use JavaScript in the browser, so we will first focus on getting you acclimated to this different environment. When we are done, you will have a much better sense of how to separate the JS programming language from browser-specific and Node-specific features.

  • Not a browserWelcome and Tech Check

    We'll get set up and ensure everyone has the required software installed.

  • Not a browserProcess, Arguments, Input and Output

    In Node.js, process is a global that provides information about your running Node program. Think of it as the server-side equivalent to a web browser’s window global.

    Many programming languages have a single “entry” point function (often called main). JavaScript is a little different, in that a module’s code is executed as soon as it is imported for the first time from somewhere else. As a result, the arguments passed to the program, the ability to print to the console and the ability to receive keyboard input are available throughout your node app.

  • Not a browserEXERCISE: Magic 8 Ball

    Write a Node.js program that prompts the user for a question, and responds with a random answer. If the user provides something that doesn’t seem like a question, your program should use process.stderr to tell the user their input is invalid, and allow them to try again.

  • Not a browserAsync Control Flow

    While promises and async/await have become the preferred way to manage asynchronous jobs, nearly all of the asynchronous functions in Node.js core libraries require a callback to be passed as an argument. We’ll compare different ways of managing concurrency, and hone in on today’s best practices.

  • Not a browserEXERCISE: Promisify

    Modern versions of Node.js include a promisify utility function, which converts a node-callback-style function into a promise-emitting function. However, as a workshop instructor, I need to be able to support Node versions that don’t come with this! Write me a promisify, and make sure that errors are handled properly.

  • Not a browserThe REPL and Debugging

    The Node Read-Eval-Print-Loop (REPL) allows developers to execute statements in an interactive environment. We’ll learn how to make the REPL work for you, and a popular workflow involving prototyping code in isolation before bringing it into your program.

    One of the major differences in how JavaScript is developed for Node and the browser is the debugging process. We’ll learn how to use Visual Studio Code and launch configurations to turn this amazing code editor into a lightweight IDE!

  • Not a browserEXERCISE: Bug Hunt

    You’ll be given a program with a bug that slipped by all of our static code analysis. Set up a Visual Studio Code debugging configuration so that you can “launch” the program from within the editor. Use your knowledge of conditional breakpoints and restarting stack frames to track down the malfunction.

  • Not a browserLunch

    Break for lunch