This book is about shell scripting with Node.js. You will learn:
- How Node.js works:
- Its foundations: its architecture, its event loop, etc.
- Its API: How to use its global variables and modules.
- What npm packages (the de-facto standard for JavaScript packages) are.
- How to use npm (the package manager bundled with Node.js) to:
- Install and manage packages.
- Create and publish packages.
- How to write cross-platform package scripts for running development tasks such as generating artifacts and running tests.
- How to use all of the aforementioned knowledge to create and deploy cross-platform shell scripts.
- Title
- Shell scripting with Node.js
- Author(s)
- Dr. Axel Rauschmayer
- Published
- 2020
- Edition
- 1
- Format
- eBook (pdf, epub, mobi)
- Pages
- 258
- Language
- English
- License
- Read online for free
- Book Homepage
- Free eBook, Errata, Code, Solutions, etc.
I About this book 1 About this book 1.1 Why should I read this book? 1.2 What knowledge is required to read this book? 1.3 Buying and previewing this book 1.4 About the author 1.5 Acknowledgements 2 Instructions 2.1 How to read this book 2.2 How assertions are used in this book II Foundations 3 Getting started with Node.js 3.1 Getting help for Node.js 3.2 Installing Node.js and npm 3.3 Running Node.js code 4 An overview of Node.js: architecture, APIs, event loop, concurrency 4.1 The Node.js platform 4.2 The Node.js event loop 4.3 libuv: the cross-platform library that handles asynchronous I/O (and more) for Node.js 4.4 Escaping the main thread with user code 4.5 Sources of this chapter 5 Packages: JavaScript’s units for software distribution 5.1 What is a package? 5.2 The file system layout of a package 5.3 Archiving and installing packages 5.4 Referring to modules via specifiers 5.5 Module specifiers in Node.js 6 An overview of npm (a package manager for JavaScript) 6.1 The npm package manager 6.2 Getting help for npm 6.3 Common npm commands 6.4 Abbreviations for npm commands III Core Node.js functionality 7 Working with file system paths and file URLs on Node.js 7.1 Path-related functionality on Node.js 7.2 Foundational path concepts and their API support 7.3 Getting the paths of standard directories via module 'node:os' 7.4 Concatenating paths 7.5 Ensuring paths are normalized, fully qualified, or relative 7.6 Parsing paths: extracting various parts of a path (filename extension etc.) 7.7 Categorizing paths 7.8 path.format(): creating paths out of parts 7.9 Using the same paths on different platforms 7.10 Using a library to match paths via globs 7.11 Using file: URLs to refer to files 8 Working with the file system on Node.js 8.1 Concepts, patterns and conventions of Node’s file system APIs 8.2 Reading and writing files 8.3 Handling line terminators across platforms 8.4 Traversing and creating directories 8.5 Copying, renaming, moving files or directories 8.6 Removing files or directories 8.7 Reading and changing file system entries 8.8 Working with links 8.9 Further reading 9 Native Node.js streams 9.1 Recap: asynchronous iteration and asynchronous generators 9.2 Streams 9.3 Readable streams 9.4 Transforming readable streams via async generators 9.5 Writable streams 9.6 Quick reference: stream-related functionality 9.7 Further reading and sources of this chapter 10 Using web streams on Node.js 10.1 What are web streams? 10.2 Reading from ReadableStreams 10.3 Turning data sources into ReadableStreams via wrapping 10.4 Writing to WritableStreams 10.5 Turning data sinks into WritableStreams via wrapping 10.6 Using TransformStreams 10.7 Implementing custom TransformStreams 10.8 A closer look at backpressure 10.9 Byte streams 10.10 Node.js-specific helpers 10.11 Further reading 11 Stream recipes 11.1 Writing to standard output (stdout) 11.2 Writing to standard error (stderr) 11.3 Reading from standard input (stdin) 11.4 Node.js stream recipes 11.5 Web stream recipes 12 Running shell commands in child processes 12.1 Overview of this chapter 12.2 Spawning processes asynchronously: spawn() 12.3 Spawning processes synchronously: spawnSync() 12.4 Asynchronous helper functions based on spawn() 12.5 Synchronous helper functions based on spawnAsync() 12.6 Useful libraries 12.7 Choosing between the functions of module 'node:child_process' IV Working with packages 13 Installing npm packages and running bin scripts 13.1 Installing npm registry packages globally 13.2 Installing npm registry packages locally 13.3 Installing unpublished packages 13.4 npx: running bin scripts in npm packages without installing them 14 Creating cross-platform shell scripts 14.1 Required knowledge 14.2 Node.js ESM modules as standalone shell scripts on Unix 14.3 Creating an npm package with shell scripts 14.4 How npm installs shell scripts 14.5 Publishing the example package to the npm registry 14.6 Standalone Node.js shell scripts with arbitrary extensions on Unix 14.7 Standalone Node.js shell scripts on Windows 14.8 Creating native binaries for Linux, macOS, and Windows 14.9 Shell paths: making sure shells find scripts 15 Running cross-platform tasks via npm package scripts 15.1 npm package scripts 15.2 Kinds of package scripts 15.3 The shell environment in which package scripts are run 15.4 Using environment variables in package scripts 15.5 Arguments for package scripts 15.6 The npm log level (how much output is produced) 15.7 Cross-platform shell scripting 15.8 Helper packages for common operations 15.9 Expanding the capabilities of package scripts 15.10 Sources of this chapter V Handling common tasks in scripting 16 Parsing command line arguments with util.parseArgs() 16.1 Imports that are implied in this chapter 16.2 The steps involved in processing command line arguments 16.3 Parsing command line arguments 16.4 parseArgs tokens 17 Shell scripting recipes 17.1 Interactively editing code snippets via nodemon 17.2 Detecting if the current module is “main” (the app entry point) 17.3 Accessing files relative to the current module 18 Cross-platform considerations 18.1 File system paths 18.2 Handling line terminators 18.3 Detecting the current platform 18.4 Running project-related tasks on all platforms
Related Books