This tutorial shows you how to prepare a local machine for Node.js development, including developing Node.js apps that run on Google Cloud. Follow this tutorial to install Node.js and relevant tools.
Objectives
- Install Node Version Manager (NVM).
- Install Node.js and npm (Node Package Manager).
- Install an editor.
- Install the Google Cloud CLI.
- Install the Cloud Client Libraries for Node.js.
- Set up authentication.
Installing NVM
NVM is a bash script for managing installations of Node.js and npm
. NVM doesn't
support Windows. For more information about managing your Node.js installation
on Windows, see nvm-windows.
For details on installing NVM, see the installation instructions.
Installing Node.js and npm
Once NVM is installed, you can install Node.js and npm.
To install the latest version of Node.js, run the following:
nvm install stable
Optional: To make this version your default version, run the following:
nvm alias default stable
Optional: To check what version of Node.js that you're running, run the following:
node -v
npm is the Node Package Manager for Node.js and is normally installed alongside Node.js. You use npm to install Node.js packages from the npm repository. For example:
npm install --save express
Installing an editor
There are several editors that you can use to develop Node.js apps. A few popular ones include the following:
- Visual Studio Code by Microsoft
- IntelliJ IDEA and/or Webstorm by JetBrains
For effective Node.js development, these editors offer features (sometimes with the help of plugins) that range from syntax highlighting, intelli-sense, and code completion to fully integrated debugging capabilities.
Installing the Google Cloud CLI
The gcloud CLI is a set of tools for Google Cloud. It contains gcloud
and bq
, which you can use to access Compute Engine,
Cloud Storage, BigQuery, and other products and services from
the command line. You can run these tools interactively or in your automated
scripts.
For example, the following command deploys any Node.js web application to the
App Engine standard environment. After deployment App Engine
attempts to start the app with npm start
.
gcloud app deploy
Installing the Cloud Client Libraries for Node.js
The Cloud Client Libraries for Node.js are the idiomatic ways for Node.js developers to integrate with Google Cloud services such as Datastore and Cloud Storage. For example, you can install the package for an individual API by using the following:
npm install --save @google-cloud/storage
Set up authentication
To use the Cloud Client Libraries in a local development environment, set up Application Default Credentials.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Authenticate for using client libraries.
What's next
- Browse the documentation for Google Cloud products.
- Clone the Node.js samples repository from GitHub.
- Explore Node.js tutorials submitted by the community.