The Fastly CLI is the recommended tool provided by Fastly for interacting with the Fastly API from the command line. It’s an open-source tool used by developers and in continuous integration pipelines to perform various actions on behalf of a Fastly account, including creating services, managing backends and domains, and deploying Compute packages. If you’re working with Fastly Compute in JavaScript, we have exciting news that brings the Fastly CLI closer to you – the Fastly CLI is now available as a package on npm.
It’s been an exciting three years since we announced JavaScript support in the Fastly Compute edge platform, and almost two years since we released v1.0 of the JavaScript SDK. It’s a very popular language on the platform and also happens to be my personal favorite. Developing for Fastly Compute using JavaScript enables the creation of edge applications in a quick and fun way, and we want to extend access to it to as many users as we can.
As a developers-first company, there is one thing we always have on our minds: to remove as many obstacles as possible from getting in the way of actual development. That is, how can we enable developers to get the job done with one fewer click, with one fewer dependency, with one fewer tool needed to be installed? Is there a way to make JavaScript development on Compute simpler? That’s what we set out to tackle this time.
The Fastly CLI is an open-source tool used to perform actions with your Fastly account. Since it’s used for running and publishing Compute applications, it is one of the requirements for developing for Fastly Compute in JavaScript, even if it’s just to try it out locally. This has traditionally meant a trip to the GitHub repository to obtain a prebuilt package, or installing it through Homebrew on macOS. While these are steps that are generally familiar to developers, we wanted to lower the barrier as much as we can for getting your feet wet in Compute application development.
That’s why starting with version 10.14.0, we’ve decided to publish the Fastly CLI on npmjs.org as an additional avenue of distribution. If you’re a JavaScript developer in 2024, chances are you’re familiar with npmjs.org as the de facto package repository from where you install packages into your application, whether you use yarn, pnpm, or the trusty old npm as your interface. This means npmjs.org is available by default to everyone, making it a great way for us to put this essential tool into our users’ hands.
Run the Fastly CLI without needing to install it
One handy feature of npm is npx, which allows you to run commands from npm packages without being required to install them to a project. So long as Node.js and npm are available in your environment, you can now directly invoke the Fastly CLI as such:
npx @fastly/cli
The first time you do this, you will be prompted by npm to fetch the package; this will add it to your environment’s npm cache, and it will be available immediately in the future.
Since the Fastly CLI is always called with additional parameters, you just specify them as normal as parameters following the command. For example, to list the services in your Fastly account, you can type:
npx @fastly/cli service list
Fastly CLI as a dependency package
Of course, availability on npmjs.org means you can now add the Fastly CLI to your Compute JavaScript application as a standard dependency:
npm install @fastly/cli
Alternatively, you can add it to your project’s package.json file:
{ "dependencies": { "@fastly/cli": "^10.14.0" } }
Then install the dependencies for the project:
npm install
This installs @fastly/cli as a dependency into your project’s node_modules directory. It becomes available as a program called fastly under the node_modules/.bin subdirectory, so you will be able to invoke it like this:
npx fastly
For example, to start your application in the local development environment, type the following:
npx fastly compute serve
Additionally, any references to fastly in the scripts section of the package.json file will now find this locally installed version of @fastly/cli instead of requiring a global installation of the Fastly CLI to be available on the system.
{ "scripts": { "build": "js-compute-runtime src/index.js bin/main.wasm", "start": "fastly compute serve", "deploy": "fastly compute publish" } }
No global installation necessary
Traditionally, it has been necessary for every developer working with Fastly Compute to install a globally available instance of the Fastly CLI to develop applications and publish them to their Fastly account, even when just getting started with the platform to experiment. By making the Fastly CLI available as a standard dependency to a JavaScript application, first-time users of Fastly Compute can experience a Compute application by simply cloning its application repository, installing its dependencies as normal, and typing npm start. In fact, we have updated all our JavaScript and TypeScript starter kits to take this approach, so that they can be experienced by more users, even if they have no prior experience with the Compute platform.
It’s also great when you work in a team. You, as well as other developers who work with your application, can obtain your application’s code, use the standard procedure to install its dependencies, and get right to work, batteries included.
This convenience extends to your continuous integration (CI) pipeline as well, enabling your application to have reliable access to the Fastly CLI as part of its build or test process.
Use new features of the CLI with confidence
The Fastly CLI is under active development, constantly receiving new features and improvements.
Specifying the Fastly CLI as a standard dependency of your package enables you to prescribe its version using semantic versioning. This allows your package to safely depend on features of the CLI that have been added recently or whose behavior may have changed, without having to worry about whether other developers who work with your application have a compatible version of the CLI installed on their environments.
Calling the Fastly CLI from Node.js code
If you are writing code intended to run under Node.js that calls out to the Fastly CLI, such as in a tool or utility program, this package provides a very straightforward and reliable way to do so.
The default export of @fastly/cli resolves to a string value representing the full path of the executable of the Fastly CLI, appropriate for the operating system, architecture, and how it has been installed. It can be used directly with functions such as spawnSync in Node.js. Because this is available in this way, you don’t need to have the user of your package obtain a global installation of the Fastly CLI before running your program.
The following example Node.js program executes the fastly version command:
npx @fastly/cli
Even install the Fastly CLI globally
If you ever do need a global installation of the Fastly CLI, this package also acts as one way of obtaining it for global use:
npx @fastly/cli service list
Once it’s installed, invoke it as you would have done traditionally:
{ "dependencies": { "@fastly/cli": "^10.14.0" } }
Under the hood, this is no different than invoking the copy of the CLI cached in the environment using npx @fastly/cli. However, this procedure makes the command available as fastly on the system path, enabling it to fit with other tools that expect to find it there. The end result is effectively identical to if you had used any of the traditional methods of global installation, but this installation process is a convenient alternative, as npm is widely available on many machines.
Bringing edge computing to more developers
At Fastly, we strive to provide the tools that give you the power to run more code at the edge and develop for it with the tools you know and love. We want nothing to get in the way of this. As JavaScript is the most popular language on the planet, the release of the Fastly CLI on npm moves the needle further along this mission.
We love to hear about it when our users get the most out of these tools. Get your free Fastly developer account, join us on the Fastly community forum, and let us know what you’ve been building!
The above is the detailed content of Fastly CLI on npm: now at your JavaScript fingertips. For more information, please follow other related articles on the PHP Chinese website!

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
