How To Code in Node.js

342.6k views

Node.js is a popular open-source runtime environment that can execute JavaScript outside of the browser. The Node runtime is commonly used for back-end web development, leveraging its asynchronous capabilities to create networking applications and web servers. Node also is a popular choice for building command line tools.

In this series, you will go through exercises to learn the basics of how to code in Node.js, gaining powerful tools for back-end and full stack development in the process.

  • Node.js is a popular open-source runtime environment that can execute JavaScript outside of the browser using the V8 JavaScript engine, which is the same engine used to power the Google Chrome web browser's JavaScript execution. In this tutorial you'll create your first program with the Node.js runtime. You'll be introduced to a few Node-specific concepts and build your way up to create a program that helps users inspect environment variables on their system.
  • September 17, 2019
    The Node.js Read-Eval-Print-Loop (REPL) is an interactive shell that processes Node.js expressions. The shell reads JavaScript code the user enters, evaluates the result of interpreting the line of code, prints the result to the user, and loops until the user signals to quit. The REPL is bundled with with every Node.js installation and allows you to quickly test and explore JavaScript code within the Node environment without having to store it in a file.
  • The Node.js Package Manager (npm) is the default and most popular package manager in the Node.js ecosystem, and is primarily used to install and manage external modules in a Node.js project. In this tutorial, you will manage packages with npm, first keeping track of modules with the package.json file, and then using the npm CLI tool to list your package dependencies, update your packages, uninstall your packages, and perform an audit to find security flaws in your packages.
  • November 26, 2019
    In Node.js, a module is a collection of JavaScript functions and objects that can be used by external applications. In this tutorial, you will create a Node.js module organized with npm that suggests what color web developers should use in their designs. You will develop the module by storing the colors as an array, and providing a function to retrieve one randomly. Afterwards, you will run through various ways of exporting and importing a module into a Node.js application.
  • With asynchronous programming, JavaScript and Node.js developers can execute other code while waiting for activities like network requests to finish. This can make writing API calls much more efficient. In this tutorial, you will learn how JavaScript manages asynchronous tasks with help from the Event Loop. You will then create a program that uses asynchronous programming written in three ways: with callbacks, promises, and the async/await keywords.
  • Testing is an integral part of software development. With the right test setup, this process can be automated, saving a lot of time. In this article, you'll write tests for a Node.js TODO list module. You will set up and use the Mocha test framework to structure a series of integration tests. Then you'll use the Node.js assert module to create the tests themselves. Finally, you will try out testing with asynchronous code, and use hooks to prepare your test fixtures and environments.
  • Node.js allows developers to use JavaScript to write back-end code, even though traditionally it was used in the browser to write front-end code. Having both the frontend and backend together like this reduces the effort it takes to make a web server. In this tutorial, you will learn how to build web servers using the http module that's included in Node.js. You will build web servers that can return JSON data, CSV files, and HTML web pages.
  • April 29, 2020
    A buffer is a space in memory (typically RAM) that stores binary data. In Node.js, we can access these spaces of memory with the built-in Buffer class. Buffers are useful when using JavaScript to interacting with binary data, usually at lower networking levels. In this tutorial, you will use the Node.js REPL to create buffers, read from buffers, write to and copy from buffers, and use buffers to convert between binary data and data encoded with ASCII and UTF-8.
  • Event emitters are objects in Node.js that trigger an event by sending a message to signal that an action was completed. In this article, you will create an event listener for a TicketManager JavaScript class that allows a user to buy tickets. You will set up listeners for the buy event, which will trigger every time a ticket is bought. This process will also teach you how to manage erroneous events from the emitter and how to manage event subscribers.
  • In this article, you will use a debugger to debug some sample Node.js applications. You will first debug code using the built-in Node.js debugger tool, setting up watchers and breakpoints so you can find the root cause of a bug. You will then use Google Chrome DevTools as a Graphical User Interface (GUI) alternative to the command line Node.js debugger.
  • Since Node.js instances create a single process with a single thread, JavaScript operations that take a long time to run can sometimes block the execution of other code. A key strategy to work around this problem is to launch a child process to run multiple processes concurrently. In this tutorial, you will use the child_process module to create child processes while executing a series of sample Node.js applications.
  • With Node.js, you can use JavaScript to programmatically manipulate files with the built-in fs module. The name is short for "file system," and the module contains all the functions you need to read, write, and delete files on the local machine. In this article, you will use the asynchronous fs module to read a file with fs.readFile(), create and write to a new file with fs.writeFile(), delete the file with fs.unlink(), and move the first file with fs.rename().