This tutorial shows how to prepare your local machine for Node.js development, including developing Node.js applications that run on Google Cloud Platform. Follow this tutorial to install Node.js and relevant tools.
Read Node.js and Google Cloud Platform to get an overview of Node.js itself and learn ways to run Node.js apps on Google Cloud Platform.
- Install Node Version Manager (NVM)
- Install Node.js and npm (Node Package Manager)
- (Optional) install Yarn
- Install an editor
- Install the Google Cloud SDK
- Install the Google Cloud Client Library for Node.js
- Install other useful tools
Install Node Version Manager (NVM)
Node Version Manager (NVM) is a simple bash script for managing installations of Node.js and npm. NVM does not support Windows; check out nvm-windows for managing your Node.js installation on Windows.
Installing NVM is simple; check out the installation instructions for details on installing NVM on your platform.
Install Node.js and npm (Node Package Manager)
Once NVM is installed you can install Node.js and npm. To install the latest stable version of Node.js you would run:
nvm install stable
To make it the default version run the following:
nvm alias default stable
You can check what version of Node.js you're running with:
npm is the Node Package Manager for Node.js and should have been installed alongside Node.js. You use npm to install Node.js packages from the npm repository, for example:
npm install --save express
For additional reading, read Run Express.js on Google Cloud Platform.
(Optional) install Yarn
Yarn is an alternative Node.js package manager that boasts faster install times and reliably reproducible builds. Installing Yarn is simple; check out the installation instructions for details on installing Yarn on your platform.
The following command uses Yarn to install the
yarn add express
Yarn automatically updates your
package.json file and produces a
file (a list of installed dependencies and transitive dependencies) which you
should commit to version control. See also
Using Yarn on Google App Engine.
Install an editor
Popular editors (in no particular order) used to develop Node.js applications include, but are not limited to:
- Sublime Text by Jon Skinner
- Atom by GitHub
- Visual Studio Code by Microsoft
- IntelliJ IDEA and/or Webstorm by JetBrains
These editors (sometimes with the help of plugins) give you everything from syntax highlighting, intelli-sense, and code completion to fully integrated debugging capabilities, maximizing your Node.js development efficacy.
Install the Google Cloud SDK
The Google Cloud SDK is a set of tools for Google Cloud Platform. It
bq, which you can use to access Google
Compute Engine, Google Cloud Storage, Google BigQuery, and other products and
services from the command line. You can run these tools interactively or in your
As an example, here is a simple command that will deploy any Node.js web
application to Google App Engine flexible environment (after deployment App
Engine will attempt to start the application with
gcloud app deploy
Install the Google Cloud Client Library for Node.js
The Google Cloud Client Library for Node.js is the idiomatic way for Node.js developers to integrate with Google Cloud Platform services, like Cloud Datastore and Cloud Storage. You can install the package for an individual API, like Cloud Storage for example:
npm install --save @google-cloud/storage
During local development, your Node.js application must authenticate itself in order to interact Google Cloud Platform APIs. The easiest way to get started is to run the following command after installing the Google Cloud SDK:
gcloud auth application-default login
This saves credentials to your machine that the Cloud Client Library will automatically use to authenticate. Applications that use this method to authenticate locally will automatically be able to authenticate once deployed to Google Cloud Platform. Read more about authentication, including how authentication is handled once your application is deployed.
You'll also want to tell the Cloud Client Library which Cloud Platform Project
to use. You do this by setting the
GCLOUD_PROJECT environment variable to your
project ID, or by passing a
projectId option to the library in your code.
Install other useful tools
For a comprehensive list of amazing Node.js tools and libraries, check out the curated Awesome Node.js list.