npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@carnesen/google-cloud

v0.4.0

Published

A library for deploying websites to Google Cloud Platform

Downloads

10

Readme

A Node.js library for deploying websites and Node.js services to Google Cloud Platform (GCP) using Google App Engine

build status badge npm version badge

Features

This library can be used to automate the deployment of static websites and Node.js services to GCP with minimal configuration and just a handful of conventions. Its features include:

  • Custom domains
  • https
  • Version management
  • Low cost
  • High availability

Install

npm install @carnesen/google-cloud

The package includes runtime JavaScript files suitable for Node.js >=8 as well as the corresponding TypeScript type declarations. There are also a number of one-time manual setup steps that you'll need to do if you haven't already:

Create a project

Sign in to the Google Cloud console and create a new "project" and note its "project ID", which you'll need later.

Purchase a domain name

Use Google Domains or any other registrar to purchase a top-level domain, e.g. "example.com". Your sites and services will be served at the apex "example.com" and on subdomains "www.example.com".

Create a Cloud DNS zone

In the Google Cloud console, navigate to "Network Services" > "Cloud DNS". Follow the prompts to create a new public "zone". Note its "zone name", which you'll need later.

Delegate name resolution to Google Cloud

In the Google Cloud console, navigate to "Network Services" > "Cloud DNS". Click on the "Registrar Setup" link in the upper right-hand corner. This reveals the "NS" (name server) records for your managed zone. Copy these NS records over to your domain registrar. Details differ by provider. Here's how to do it with Google Domains.

Install the Google Cloud SDK

When the SDK is properly installed you should see, e.g.:

$ gcloud -v
Google Cloud SDK 232.0.0
bq 2.0.40
core 2019.01.27
gsutil 4.35

gcloud auth login

Sets authentication credentials for the gcloud command-line utility

gcloud auth application-default login

Sets "Application Default Credentials" for use by the @google-cloud Node.js SDKs.

gcloud config set project <project id>

Set the current active "project" for the gcloud CLI.

gcloud app create

Follow the prompts to initialize your project for "App Engine". You'll be asked to choose a region for your app. This cannot be changed later.

Usage

In the same way that your site leverages npm to version and install the library code that it uses, @carnesen/google-cloud leverages npm to version and install the site code that it deploys. This usage example assumes you've already completed the setup in the "Install" section above. We use npm to pull down the site code that we want to deploy:

npm install --save @carnesen/redirector @carnesen/www github:carnesen/meme-me @carnesen/run-and-exit

For deploying a single site, your deployment code might even be co-located with the application code in which case you wouldn't need to npm install anything beyond @carnesen/google-cloud.

Create a Node.js script deploy.js with contents:

const runAndExit = require('@carnesen/run-and-exit');
const { deployApp } = require('@carnesen/google-cloud');

// In the context of this library is an "App" is a Google Cloud
// App Engine "App", which is comprised of one or more websites
runAndExit(deployApp, {
  projectId: '<project id>',
  zoneName: '<zone name>',
  defaultSite: {
    siteType: 'nodejs',
    packageId: '@carnesen/redirector',
  },
  otherSites: [
    {
      siteType: 'static',
      siteName: 'www',
      packageId: '@carnesen/www',
    },
    {
      siteType: 'nodejs',
      siteName: 'meme-me',
      packageId: '@carnesen/meme-me',
    },
  ],
});

And run it:

$ node deploy.js
AppEngine : carnesen-tmp : Creating...
AppEngine : carnesen-tmp : Already exists
Site : default : Pre-validating...
Site : www : Pre-validating...
Site : meme-me : Pre-validating...
...

API

This project's API is documented in the form of TypeScript types and TSDoc strings.

Conventions

This project favors convention over configuration, and hopefully the conventions will align pretty well with what you're already doing. As mentioned above, for both Node.js and static sites, the site content must be in a place where require.resolve(`${packageId}/package.json`) will return the path of a package.json file. That file's containing directory is what gets uploaded to Google Cloud App Engine using gcloud app deploy.

nodejs

The package directory is uploaded to Google Cloud as-is. In particular that means that npm start should fire up your Node.js server process.

static

Similar to Node.js sites, the package directory is uploaded to Google Cloud as-is. The root of the package, however, is not what gets served by App Engine. Instead by convention it's assumed that the dist subdirectory that contains the static content that you want to serve. If that convention doesn't suit you, please just let me know and I'd be happy to parameterize it.

More information

This library doesn't have many unit tests, but I use it on a semi-regular basis to deploy sites to carnesen.com. To be sure, I don't get much traffic on those sites, but my GCP bill is typically less than a dollar a month! If you encounter any bugs or have any questions or feature requests, please don't hesitate to file an issue or submit a pull request on this project's repository on GitHub.

Related

License

MIT © Chris Arnesen