Using Yarn on App Engine
Contributed by Google employees.
Yarn is a package management tool that makes it easy and fast to install npm modules for Node.js.
You can use Yarn to manage your Node.js dependencies on App Engine flexible environment. This tutorials provides a quick demonstration.
Objectives
- Install Yarn.
- Manage Node.js dependencies with Yarn.
- Use Yarn to install dependencies during deployment to App Engine.
Costs
This tutorial uses billable components of Google Cloud, including:
- App Engine flexible environment
Use the Pricing Calculator to generate a cost estimate based on your projected usage.
Before you begin
- Create a project in the Cloud Console.
- Enable billing for your project.
- Install the Cloud SDK.
Getting started
Install Yarn by following the installation instructions.
To install a package and automatically save it to your
package.json
run:yarn add PACKAGE
For example, to install and save the
google-cloud
package:yarn add google-cloud
Running this command will save the dependency into your
package.json
, and create ayarn.lock
file in the current directory. Don't delete this file! It will track the exact version of every package you need to run your application.
Deploying to App Engine
To use Yarn for your deployments to App Engine flexible environment, all you
need is a yarn.lock
in your application directory. Then, just deploy:
gcloud app deploy
If App Engine finds a yarn.lock
in the application directory, Yarn will be
used to perform the npm installation. Learn more about the Node.js runtime for App Engine flexible environment.
And that's it! If you have any other questions about Node.js on Google Cloud, be sure to join us on our Slack channel.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.