Start your next Fastly Compute JavaScript application with npm init
Dec 28, 2024 pm 05:25 PMThe npm init (or npm create) command is a popular, platform-standard method of initializing a JavaScript application based on a template. If you’re working with JavaScript in Fastly Compute, we have exciting news for you – the npm init script for Fastly Compute gives JavaScript authors an additional way to start their Fastly Compute applications using common and standard tools.
Just over a year ago, JavaScript became a generally available language for development on Fastly Compute. With this, we have been able to bring the convenience of JavaScript to the power of the edge to developers around the world. JavaScript is a very popular language on the platform, and we want to continue to give it access to as many users as we can.
In October we announced that we have brought the Fastly CLI to npm. Today we have additional good news for JavaScript users: we now have an official npm init script for Fastly Compute!
In case you’re not familiar with npm init, it is a method of initializing a new JavaScript project based on an initialization script, built into the npm command. Fastly now provides an initializer for npm init, so it’s possible to create a new Fastly Compute project in JavaScript like this:
npm init @fastly/compute
After typing this command, you will be presented with interactive prompts to select a directory, language, and starter kit, to create your Fastly Compute application in JavaScript or TypeScript.
The initializer called by npm init @fastly/compute is a Node.js program distributed via npm under the name @fastly/create-compute. It asks questions relevant to your new JavaScript application, and then under the hood, calls the Fastly CLI to initialize your new application. No global installation of the CLI is required, however, since it declares the dependency as an npm package.
You’re already working with JavaScript, stay in the JavaScript mindset
Traditionally, the procedure to create a new Fastly Compute application has been to obtain the Fastly CLI and type the following:
fastly compute init
This meant that it was necessary for you to install a global instance of the Fastly CLI just to create a new application for Fastly Compute. You also needed it to run and publish the application. Because this was true even if you just wanted to experiment with the platform, we felt that this was sometimes getting in the way of developers wanting to try out the platform. Additionally, the Fastly CLI would prompt the selection of a programming language when initializing a new project, a potential friction point that could even take you “out of the zone” when you are already thinking in terms of JavaScript.
As always, we looked for ways to enable developers to get the job done with one fewer tool needed to be installed, with one fewer click, with one fewer dependency. Is there a way to enable JavaScript development to be even simpler? The solution was to use the standard, platform-defined npm init mechanism to allow users to initialize new applications for Fastly Compute in JavaScript.
Most JavaScript developers are already familiar with npm, since it's the tool used to install dependency packages into your application. Being able to use the npm tool to initialize a new application enables developers to stay with tools within the JavaScript ecosystem from the start of the lifetime of their application.
Batteries included!
Recently, Fastly’s JavaScript and TypeScript starter kits have been updated to install the Fastly CLI as a dependency package. This means that for most tasks you no longer need to work with the Fastly CLI directly, to run or publish your application. Instead, you are able to work with it through npm scripts.
Once your application has been initialized, use the following command to start your application:
npm init @fastly/compute
This will run fastly compute serve, which will build your application and start it under the development environment.
When you’re ready to go live, type the following command to deploy to production (for most starter kits):
fastly compute init
This will run fastly compute publish, which will build your application and publish it to your Fastly account.
Of course, if you would like to call the Fastly CLI directly, or in the case you need to perform additional functions with the Fastly CLI, such as add backends or work with edge storage, you can invoke it from within your application directory using npx:
npm run start
JavaScript edge computing = ??
At Fastly, we enjoy providing you with the power to run more code at the edge and develop for it with the tools you know and love. One fewer thing to get in the way is one more victory for us in that direction. Our initializer enabling you to create JavaScript applications for Fastly Compute using npm is another item on this journey.
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 Start your next Fastly Compute JavaScript application with npm init. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Java and JavaScript are different programming languages, each suitable for different application scenarios. Java is used for large enterprise and mobile application development, while JavaScript is mainly used for web page development.

JavaScriptcommentsareessentialformaintaining,reading,andguidingcodeexecution.1)Single-linecommentsareusedforquickexplanations.2)Multi-linecommentsexplaincomplexlogicorprovidedetaileddocumentation.3)Inlinecommentsclarifyspecificpartsofcode.Bestpractic

The following points should be noted when processing dates and time in JavaScript: 1. There are many ways to create Date objects. It is recommended to use ISO format strings to ensure compatibility; 2. Get and set time information can be obtained and set methods, and note that the month starts from 0; 3. Manually formatting dates requires strings, and third-party libraries can also be used; 4. It is recommended to use libraries that support time zones, such as Luxon. Mastering these key points can effectively avoid common mistakes.

PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl

JavaScriptispreferredforwebdevelopment,whileJavaisbetterforlarge-scalebackendsystemsandAndroidapps.1)JavaScriptexcelsincreatinginteractivewebexperienceswithitsdynamicnatureandDOMmanipulation.2)Javaoffersstrongtypingandobject-orientedfeatures,idealfor

JavaScripthassevenfundamentaldatatypes:number,string,boolean,undefined,null,object,andsymbol.1)Numbersuseadouble-precisionformat,usefulforwidevaluerangesbutbecautiouswithfloating-pointarithmetic.2)Stringsareimmutable,useefficientconcatenationmethodsf

Event capture and bubble are two stages of event propagation in DOM. Capture is from the top layer to the target element, and bubble is from the target element to the top layer. 1. Event capture is implemented by setting the useCapture parameter of addEventListener to true; 2. Event bubble is the default behavior, useCapture is set to false or omitted; 3. Event propagation can be used to prevent event propagation; 4. Event bubbling supports event delegation to improve dynamic content processing efficiency; 5. Capture can be used to intercept events in advance, such as logging or error processing. Understanding these two phases helps to accurately control the timing and how JavaScript responds to user operations.

Java and JavaScript are different programming languages. 1.Java is a statically typed and compiled language, suitable for enterprise applications and large systems. 2. JavaScript is a dynamic type and interpreted language, mainly used for web interaction and front-end development.
