/node-api

Primary LanguageJavaScriptOtherNOASSERTION

General Assembly Logo

Introduction to the Node API

Prerequisites

  • Familiarity with JavaScript as a language.
  • Familiarity with JavaScript in the browser environment.

Objectives

By the end of this, developers should be able to:

  • Reference the Node API documentation for using JavaScript outside the browser.
  • Reference the MDN JavaScript documentation for JavaScript language features.
  • Write a Node script using the File System API.

Preparation

  1. Fork and clone this repository.
  2. Install dependencies with npm install.

JavaScript, the Browser, and Node

  • JavaScript: a language specified by ECMA and implemented independently
  • Browser: an environment for running JavaScript (among other things)
  • Node: an environment for running JavaScript outside the browser

Somewhat valid equations:

Browser = JavaScript + Browser API + (other things)
   Node = JavaScript + CLI/Server API

How are the two environments similar? How do they differ?

Lab: Research the File System API

Take a few minutes to read the following API documentation for the Node File System module.

While you're reading, imagine how you'd use each function. Write some example code in your notebook. Try to explain what each function does in your own words, including what sorts of arguments it takes and each argument's type.

If you finish early, look for other interesting functions in the File System module.

  1. fs.readdir(path, callback)
  2. fs.readdirSync(path)
  3. fs.readFile(file[, options], callback)
  4. fs.writeFile(file, data[, options], callback)

Annotate-Along: lib/copy-json.js

Code-Along: hey-yall.js

"Hello, World!" with the Node file system API.

Lab: Write a Randomizer

Randomize the lines in a file.

How do you shuffle an array?

Additional Resources

Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.