<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tony Pujals</title>
    <description>The latest articles on DEV Community by Tony Pujals (@subfuzion).</description>
    <link>https://dev.to/subfuzion</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F189663%2Fc763e61c-c23a-4bb9-949e-8bcf79279570.jpeg</url>
      <title>DEV Community: Tony Pujals</title>
      <link>https://dev.to/subfuzion</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/subfuzion"/>
    <language>en</language>
    <item>
      <title>Create a blog with Deno 2 and Fresh</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Mon, 07 Oct 2024 14:13:18 +0000</pubDate>
      <link>https://dev.to/googlecloud/create-a-blog-with-deno-2-and-fresh-1lj4</link>
      <guid>https://dev.to/googlecloud/create-a-blog-with-deno-2-and-fresh-1lj4</guid>
      <description>&lt;p&gt;&lt;a href="https://fresh.deno.dev/" rel="noopener noreferrer"&gt;Fresh&lt;/a&gt; is the most popular web framework built on Deno. With the imminent &lt;a href="https://deno.com/blog/v2.0-release-candidate-update" rel="noopener noreferrer"&gt;Deno 2.0 launch&lt;/a&gt;, now is a great time to take a look at it. I give an updated dive into how to build a simple blog engine with it, based on Andy Jiang's original example.&lt;/p&gt;

&lt;p&gt;Full details are here at the GitHub &lt;a href="https://github.com/subfuzion/fresh-blog-with-deno2" rel="noopener noreferrer"&gt;repo&lt;/a&gt; and this &lt;a href="https://codesnip.sh/deno/fresh-blog-from-scratch" rel="noopener noreferrer"&gt;walkthrough&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Deploying a Fresh app to Cloud Run is straightforward, but want zero-config, managed deployments that are optimized on Google Cloud CDN infrastructure? Stay tuned for updates coming soon for deploying Fresh on &lt;a href="https://firebase.google.com/docs/app-hosting" rel="noopener noreferrer"&gt;Firebase App Hosting&lt;/a&gt; with deep integration for the latest &lt;a href="https://firebase.google.com/docs/vertex-ai" rel="noopener noreferrer"&gt;Gemini API&lt;/a&gt; generative AI models and &lt;a href="https://firebase.google.com/docs/data-connect" rel="noopener noreferrer"&gt;Data Connect&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>deno</category>
      <category>typescript</category>
      <category>fresh</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Built-in TypeScript Support with Node.js</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Tue, 24 Sep 2024 20:53:27 +0000</pubDate>
      <link>https://dev.to/googlecloud/built-in-typescript-support-with-nodejs-211l</link>
      <guid>https://dev.to/googlecloud/built-in-typescript-support-with-nodejs-211l</guid>
      <description>&lt;p&gt;Node.js 22.6.0 adds a new option for lightweight TypeScript support.&lt;/p&gt;

&lt;p&gt;What's nice about this is that it lets you maintain a simple JavaScript-type of workflow (no explicit intermediate transpilation step to generate JavaScript files from TypeScript source code) while coding in TypeScript for the benefits of static typing.&lt;/p&gt;

&lt;p&gt;Deno and Bun.js already provide a native TypeScript experience so that you can skip the explicit transpiling step. But if you're using or plan to use Node.js 22.6.0 or later, you can also take advantage of this feature.&lt;/p&gt;

&lt;p&gt;With the &lt;code&gt;--experimental-strip-types&lt;/code&gt; option, you can skip the transpilation step and directly run your .ts files. But Node.js doesn't do any actual type checking — if you want those static typing benefits previously mentioned, that's the job of a type checking tool, like the TypeScript compiler (tsc).&lt;/p&gt;

&lt;p&gt;I wrote a post on my personal blog that goes into more depth and walks through using the feature, while also supporting type checking and linting support as a developer dependency for coding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesnip.sh/posts/built-in-typescript-support-with-nodejs" rel="noopener noreferrer"&gt;https://codesnip.sh/posts/built-in-typescript-support-with-nodejs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>typescript</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Building Standalone Executables With Node.js</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Tue, 24 Sep 2024 20:34:25 +0000</pubDate>
      <link>https://dev.to/googlecloud/building-standalone-executables-with-nodejs-29l1</link>
      <guid>https://dev.to/googlecloud/building-standalone-executables-with-nodejs-29l1</guid>
      <description>&lt;p&gt;Node.js has experimental support for building a &lt;a href="https://github.com/nodejs/single-executable" rel="noopener noreferrer"&gt;single executable application&lt;/a&gt;, or SEA, which is what the team calls a standalone executable that can be distributed to &lt;a href="https://nodejs.org/api/single-executable-applications.html#platform-support" rel="noopener noreferrer"&gt;supported platforms&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The way the feature works is that a single &lt;em&gt;blob&lt;/em&gt; is injected into the &lt;code&gt;node&lt;/code&gt; binary for a supported platform. This single blob can be a JavaScript file, including multi-file JavaScript source that has been bundled with a tool like Webpack. If the blob is present, then the &lt;code&gt;node&lt;/code&gt; binary will execute the script in the blob.&lt;/p&gt;

&lt;p&gt;The recipe for building a SEA is spelled out in the &lt;a href="https://nodejs.org/api/single-executable-applications.html#single-executable-applications" rel="noopener noreferrer"&gt;docs&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Unfortunately, the developer experience is not yet on par with Deno or Bun.js. I wrote a build script to streamline building a SEA for Linux and Darwin targets and smooth out the experience. I also took a stab at the Windows target, although it's not tested.&lt;/p&gt;

&lt;p&gt;The rest of the details are on my personal blog here:&lt;br&gt;
&lt;a href="https://codesnip.sh/posts/building-standalone-nodejs-executables" rel="noopener noreferrer"&gt;https://codesnip.sh/posts/building-standalone-nodejs-executables&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The script demonstrates using Webpack for bundling. I plan to also add &lt;code&gt;esbuild&lt;/code&gt; and &lt;code&gt;swc&lt;/code&gt; support, but you can just use the project as a starting point for your own project.&lt;/p&gt;

</description>
      <category>node</category>
    </item>
    <item>
      <title>Command-Line Tools with Go: Piping Data</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Tue, 24 Sep 2024 20:21:30 +0000</pubDate>
      <link>https://dev.to/googlecloud/command-line-tools-with-go-piping-data-2jco</link>
      <guid>https://dev.to/googlecloud/command-line-tools-with-go-piping-data-2jco</guid>
      <description>&lt;p&gt;Unix is well-known for advocating the philosophy that commands should &lt;a href="https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well" rel="noopener noreferrer"&gt;do one thing and do it well&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Sophisticated data processing and transformation operations can often be performed using the shell pipe operator to chain commands together so that the output of one becomes the input of another, manipulating and transforming data to achieve a desired result.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Sort file names.
ls | sort

# Count files.
ls -l | count -l

# Print out unique file extensions.
#  1. List all files that have extensions
#  2. Transform the data (discard everything but extensions)
#  3. Sort the list (data must be sorted to identify duplicates)
#  4. Filter out duplicates
#  5. Browse the results
ls *.* | sed 's/.*\.//' | sort | uniq | less
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Go, programmers can create efficient and performant commands for processing data. We'll touch on this with the following snippets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add line numbers to output
&lt;/h2&gt;

&lt;p&gt;The essence of a command that can be used in a pipe operation is that it reads from &lt;code&gt;stdin&lt;/code&gt; and writes to &lt;code&gt;stdout&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;add-line-numbers.go&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"bufio"&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c"&gt;// Buffered input that splits input on lines.&lt;/span&gt;
    &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;bufio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewScanner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stdin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Buffered output.&lt;/span&gt;
    &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;bufio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewWriter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stdout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;lineNo&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;

    &lt;span class="c"&gt;// Scan until EOF (no more input).&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Scan&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;lineNo&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
        &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%03d %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lineNo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c"&gt;// It would be simpler to just use fmt.Println,&lt;/span&gt;
        &lt;span class="c"&gt;// but want to emphasize piping stdin to stdout&lt;/span&gt;
        &lt;span class="c"&gt;// explicitly.&lt;/span&gt;
        &lt;span class="c"&gt;// Intentionally ignoring return values.&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WriteString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Always explicitly flush remaining buffered output.&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Flush&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example reads a line at a time from &lt;code&gt;stdin&lt;/code&gt; and writes it back out to &lt;code&gt;stdout&lt;/code&gt; with each line prefixed with the line number. Here, we use the program file itself as the input to generate numbered output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cat add-line-numbers.go | go run add-line-numbers.go
001 package main
002 
003 import (
004     "bufio"
005     "fmt"
006     "os"
007 )
008 
009 func main() {
010 
011     // Buffered input that splits input on lines.
012     input := bufio.NewScanner(os.Stdin)
013 
014     // Buffered output.
015     output := bufio.NewWriter(os.Stdout)
016 
017     lineNo := 0
018 
019     // Scan until EOF (no more input).
020     for input.Scan() {
021         text := input.Text()
022         lineNo++
023         s := fmt.Sprintf("%03d %s\n", lineNo, text)
024 
025         // It would be simpler to just use fmt.Println,
026         // but want to emphasize piping stdin to stdout
027         // explicitly.
028         // Intentionally ignoring return values.
029         _, _ = output.WriteString(s)
030 
031     }
032 
033     // Always explicitly flush remaining buffered output.
034     _ = output.Flush()
035 
036 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Base64 encode input
&lt;/h2&gt;

&lt;p&gt;This example reads a line at a time from &lt;code&gt;stdin&lt;/code&gt;, base64 encodes it, and writes it back out to &lt;code&gt;stdout&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"bufio"&lt;/span&gt;
    &lt;span class="s"&gt;"encoding/base64"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c"&gt;// Buffered input that splits input on lines.&lt;/span&gt;
    &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;bufio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewScanner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stdin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Base64 Encoder/writer.&lt;/span&gt;
    &lt;span class="n"&gt;encoder&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewEncoder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;StdEncoding&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stdout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Scan until EOF (no more input).&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Scan&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Bytes&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;encoder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;encoder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;([]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sc"&gt;'\n'&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Close the encoder and ensure it flushes remaining output&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;encoder&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the scanner splits on newline characters (&lt;code&gt;\n&lt;/code&gt;) without returning them, it's necessary to explicitly write a newline after writing each line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cat base64-encode.go | go run base64-encode.go
cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImJ1ZmlvIgoJImVuY29kaW5nL2Jhc2U2NCIKCSJvcyIKKQoKZnVuYyBtYWluKCkgewoKCS8vIEJ1ZmZlcmVkIGlucHV0IHRoYXQgc3BsaXRzIGlucHV0IG9uIGxpbmVzLgoJaW5wdXQgOj0gYnVmaW8uTmV3U2Nhbm5lcihvcy5TdGRpbikKCgkvLyBCYXNlNjQgRW5jb2Rlci93cml0ZXIuCgllbmNvZGVyIDo9IGJhc2U2NC5OZXdFbmNvZGVyKAoJCWJhc2U2NC5TdGRFbmNvZGluZywKCQlvcy5TdGRvdXQpCgoJLy8gU2NhbiB1bnRpbCBFT0YgKG5vIG1vcmUgaW5wdXQpLgoJZm9yIGlucHV0LlNjYW4oKSB7CgkJYnl0ZXMgOj0gaW5wdXQuQnl0ZXMoKQoJCV8sIF8gPSBlbmNvZGVyLldyaXRlKGJ5dGVzKQoJCV8sIF8gPSBlbmNvZGVyLldyaXRlKFtdYnl0ZXsnXG4nfSkKCX0KCgkvLyBDbG9zZSB0aGUgZW5jb2RlciBhbmQgZW5zdXJlIGl0IGZsdXNoZXMgcmVtYWluaW5nIG91dHB1dAoJXyA9IGVuY29kZXIuQ2xvc2UoKQp9Cg==
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can confirm the text was correctly encoded by piping the encoded result to the system &lt;code&gt;base64&lt;/code&gt; command (Linux and MacOS) to decode it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cat base64-encode.go | go run base64-encode.go | base64 -D
package main

import (
    "bufio"
    "encoding/base64"
    "os"
)

func main() {

    // Buffered input that splits input on lines.
    input := bufio.NewScanner(os.Stdin)

    // Base64 Encoder/writer.
    encoder := base64.NewEncoder(
        base64.StdEncoding,
        os.Stdout)

    // Scan until EOF (no more input).
    for input.Scan() {
        bytes := input.Bytes()
        _, _ = encoder.Write(bytes)
        _, _ = encoder.Write([]byte{'\n'})
    }

    // Close the encoder and ensure it flushes remaining output
    _ = encoder.Close()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This post is an excerpt from a short, introductory guide I wrote on standard library features of Go that are useful for creating command line tools: &lt;a href="https://codesnip.sh/go/command-line-programs/commands" rel="noopener noreferrer"&gt;Go for CLI Apps and Tools&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Cloud Run - basic logging for your TypeScript app</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Fri, 01 Dec 2023 23:21:45 +0000</pubDate>
      <link>https://dev.to/subfuzion/cloud-run-add-logging-to-your-typescript-app-18ic</link>
      <guid>https://dev.to/subfuzion/cloud-run-add-logging-to-your-typescript-app-18ic</guid>
      <description>&lt;p&gt;In the &lt;a href="https://dev.to/subfuzion/cloud-run-typescript-boilerplate-for-getting-started-4gco"&gt;previous article&lt;/a&gt;, you deployed your TypeScript app to Cloud Run.&lt;/p&gt;

&lt;p&gt;Cloud Run will capture basic logs based on what you print to &lt;code&gt;stdout&lt;/code&gt; and &lt;code&gt;stderr&lt;/code&gt;, generally what you write using &lt;code&gt;console.log&lt;/code&gt; and &lt;code&gt;console.error&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After deploying the app, you can use a new gcloud command that's currently in beta to read or even tail your logs.&lt;/p&gt;

&lt;p&gt;First, ensure you've got beta support:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud components install beta
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Or, if you already had it installed, but just want to update:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud components update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now you can read your logs:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud beta run services logs read [SERVICE] \
  --project=[PROJECT] \
  --region=[REGION] \
  --limit=10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You should see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgqt4iksqy2tn3kg8ouo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgqt4iksqy2tn3kg8ouo.png" alt="log output" width="800" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also tail your logs:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud beta run services logs tail blogdemo --project javascript-demos
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And, of course, now every time you send a request, you'll see a log entry print to your terminal, similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexzq5oml2wr5cpg1j7gk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexzq5oml2wr5cpg1j7gk.png" alt="Image description" width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the project that you generated in the previous article, update the &lt;code&gt;logs&lt;/code&gt; and &lt;code&gt;logs:tail&lt;/code&gt; scripts in package.json with the values you used for &lt;code&gt;deploy&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[SERVICE]&lt;/code&gt; - the name of your service&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[PROJECT]&lt;/code&gt; - your cloud project ID&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[REGION]&lt;/code&gt; - the region you deployed to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then you can run either &lt;code&gt;npm logs&lt;/code&gt; or &lt;code&gt;npm logs:tail&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;In the next article, you'll see how you can get more value out of your logs using structured logging, which among other things, will help you correlate logs by HTTP request.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cloud Run - TypeScript boilerplate for getting started</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Fri, 01 Dec 2023 22:27:57 +0000</pubDate>
      <link>https://dev.to/subfuzion/cloud-run-typescript-boilerplate-for-getting-started-4gco</link>
      <guid>https://dev.to/subfuzion/cloud-run-typescript-boilerplate-for-getting-started-4gco</guid>
      <description>&lt;p&gt;My goal for this article is to help you get started writing TypeScript apps that you can deploy to Cloud Run.&lt;/p&gt;

&lt;p&gt;Because Google Cloud documentation is tailored primarily for JavaScript, it's not necessarily clear to developers that you can write TypeScript and deploy from source code to Cloud Run as long as you your &lt;code&gt;package.json&lt;/code&gt; has the following &lt;a href="https://docs.npmjs.com/cli/v10/using-npm/scripts" rel="noopener noreferrer"&gt;two run scripts&lt;/a&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;build&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;start&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So if you just want to add a &lt;a href="https://www.typescriptlang.org/docs/handbook/tsconfig-json.html" rel="noopener noreferrer"&gt;tsconfig.json&lt;/a&gt;, use &lt;a href="https://www.typescriptlang.org/docs/handbook/compiler-options.html" rel="noopener noreferrer"&gt;tsc&lt;/a&gt; in the &lt;code&gt;build&lt;/code&gt; script to transform TypeScript to JavaScript, and indicate which JavaScript file to run in your &lt;code&gt;start&lt;/code&gt; script, then all you need to do to deploy a public service from your source is run the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud run deploy [SERVICE] \
  --project [PROJECT] \
  --region [REGION] \
  --allow-unauthenticated \
  --source .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;But I'd like to help you more than that. I've created a repo (&lt;a href="https://github.com/subfuzion/cloud-run-app" rel="noopener noreferrer"&gt;cloud-run-app&lt;/a&gt;) that contains boilerplate for a starter project.&lt;/p&gt;

&lt;p&gt;You don't need to clone the repo. You can generate a new app on your machine with the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-cloud-run-app [PATH]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;path&lt;/code&gt; isn't specified, it defaults to the current working directory (&lt;code&gt;.&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;The directory under &lt;code&gt;PATH&lt;/code&gt; must be empty&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal for this generator is to give you a bit of opinionated structure, but not too much:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your TypeScript code goes under &lt;code&gt;src&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Your tests (&lt;code&gt;*.test.ts&lt;/code&gt;) can go under &lt;code&gt;src&lt;/code&gt; or &lt;code&gt;test&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Your generated output goes under &lt;code&gt;dist&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I use &lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;Express&lt;/a&gt; and &lt;a href="https://jestjs.io/" rel="noopener noreferrer"&gt;Jest&lt;/a&gt;, but only enough to give you something to start with. You can substitute these out for your favorite web and test framework.&lt;/p&gt;

&lt;p&gt;In fact, Express is the only one of two dependencies (the other is a cloud logging library). All the other dependencies are &lt;a href="https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file" rel="noopener noreferrer"&gt;devDependencies&lt;/a&gt; and they are there to provide you with comprehensive compiling, testing, linting, and formatting support.&lt;/p&gt;

&lt;p&gt;This is arguably the real value of using this boilerplate, since configuring the integration of TypeScript, editorconfig, eslint, prettier, and Jest so that everything plays well together is a bit challenging. &lt;/p&gt;

&lt;p&gt;For me, it's been a cumulative effort over various projects this past year, but if I had to pin down the effort, I feel that it took days or even a week of toil banging at configuration.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Side note: I'm totally open to any suggestions if you see ways to improve the configuration. Although you can leave comments below, it would be even better to open an issue or &lt;a href="https://github.com/subfuzion/cloud-run-app/discussions" rel="noopener noreferrer"&gt;start a discussion&lt;/a&gt; in the repo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go ahead and inspect the generated package.json (or run &lt;code&gt;npm run-script&lt;/code&gt;), but you these are the main scripts to be aware of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;build&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;test&lt;/code&gt; | &lt;code&gt;test:watch&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;deploy&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Trying it out
&lt;/h2&gt;

&lt;p&gt;First run &lt;code&gt;npm test&lt;/code&gt; to verify the very simple integration smoke tests pass.&lt;/p&gt;

&lt;p&gt;Then, if you haven't already gotten set up with a Google Cloud project so you can deploy to Cloud Run, go see the previous article: &lt;a href="https://dev.to/subfuzion/cloud-run-getting-started-checklist-4c6o"&gt;Cloud Run - getting started checklist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you have a cloud project, update the &lt;code&gt;.cloudconfig&lt;/code&gt; file in your generated project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: if you want to update &lt;code&gt;.cloudconfig&lt;/code&gt;, but not accidentally commit it, then make a copy and call it &lt;code&gt;cloudconfig&lt;/code&gt;. This is automatically ignored by &lt;code&gt;.gitignore&lt;/code&gt;. Going forward, I'll assume you did this and just refer to &lt;code&gt;cloudconfig&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'll need to set the following variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;SERVICE&lt;/code&gt; - with the name for your service&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PROJECT&lt;/code&gt; - with your cloud project ID&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;REGION&lt;/code&gt; - with the &lt;a href="https://cloud.google.com/run/docs/locations" rel="noopener noreferrer"&gt;region&lt;/a&gt; to deploy to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After updating &lt;code&gt;cloudconfig&lt;/code&gt;, source the variables into your bash environment:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source cloudconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then run:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Answer yes to any prompts about enabling APIs and creating a repo in the project to store the app container image.&lt;/p&gt;

&lt;p&gt;You should see output similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filnk7p4vfvtljo2yee8x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Filnk7p4vfvtljo2yee8x.png" alt="deploy output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last line of output contains the service URL. Go ahead and open the link in a browser. You should see an "ok" response.&lt;/p&gt;

&lt;p&gt;Congratulations, you have a starter project configured for TypeScript that you can deploy to Cloud Run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;In the next article, add cloud logging support.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cloud Run - getting started checklist</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Fri, 01 Dec 2023 22:26:55 +0000</pubDate>
      <link>https://dev.to/subfuzion/cloud-run-getting-started-checklist-4c6o</link>
      <guid>https://dev.to/subfuzion/cloud-run-getting-started-checklist-4c6o</guid>
      <description>&lt;p&gt;To get started developing for &lt;a href="https://cloud.google.com/run" rel="noopener noreferrer"&gt;Cloud Run&lt;/a&gt;, you need to take of a number of administrative steps first.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I've edited the original article to move the Recap to the top and rename it to Checklist. This is all you need. The rest of the article is here to provide you with extra detail if it's your first time running through the checklist.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;p&gt;Sign up for GCP&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign in with a Google account&lt;/li&gt;
&lt;li&gt;Create a billing account&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Set up your machine&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the Google Cloud CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Set up a cloud project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Log in at the terminal:&lt;/p&gt;

&lt;p&gt;gcloud auth login&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a project&lt;/p&gt;

&lt;p&gt;gcloud projects create PROJECT_ID&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Link the project to a billing account&lt;/p&gt;

&lt;p&gt;gcloud billing projects link PROJECT_ID --billing-account ACCOUNT_ID&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Delete the project when no longer needed&lt;/p&gt;

&lt;p&gt;gcloud projects delete PROJECT_ID&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Checklist walkthrough
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://cloud.google.com/run/docs" rel="noopener noreferrer"&gt;Cloud Run Documentation&lt;/a&gt; is the ultimate source of truth, but I created this article as a checklist to help developers who are new to the platform get set up for a following series of Cloud Run blog posts that will refer to this as a prerequisite.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign up for GCP&lt;/li&gt;
&lt;li&gt;Set up your machine&lt;/li&gt;
&lt;li&gt;Set up a cloud project&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Sign up for GCP
&lt;/h2&gt;

&lt;p&gt;To use GCP, you'll need to sign up:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign in with a Google account&lt;/li&gt;
&lt;li&gt;Create a billing account&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Sign in with a Google account
&lt;/h3&gt;

&lt;p&gt;Go to &lt;a href="https://cloud.google.com/" rel="noopener noreferrer"&gt;Google Cloud Platform&lt;/a&gt;, click &lt;strong&gt;Get started for free&lt;/strong&gt;, and sign in with a Google account. If you don't already have a Google account, then click &lt;strong&gt;Create account&lt;/strong&gt; and follow the prompts.&lt;/p&gt;

&lt;p&gt;When you activate a GCP account, you get access to both of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/free/docs/free-cloud-features#free-trial" rel="noopener noreferrer"&gt;Free Trial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/free/docs/free-cloud-features#free-tier" rel="noopener noreferrer"&gt;Free Tier&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Currently, the Free Trial provides $300 of Cloud Billing credits to pay for resources for ninety days while you explore GCP.&lt;/p&gt;

&lt;p&gt;The Free Tier provides access to GCP products for free beyond the free trial as long as you stay below the &lt;a href="https://cloud.google.com/free/docs/free-cloud-features#free-tier-usage-limits" rel="noopener noreferrer"&gt;Free Tier usage limits&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For more details, see &lt;a href="https://cloud.google.com/free/docs/free-cloud-features" rel="noopener noreferrer"&gt;Google Cloud Free Program&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a billing account
&lt;/h3&gt;

&lt;p&gt;If you use the free trial, Google creates a billing account for you and applies the free credits to your account.&lt;/p&gt;

&lt;p&gt;Once the free trial period ends, you can continue to use the free tier, but you're required to set up a billing account to cover any costs that exceed free tier usage limits.&lt;/p&gt;

&lt;p&gt;If you need to create a billing account, go to &lt;a href="https://console.cloud.google.com/billing" rel="noopener noreferrer"&gt;Billing&lt;/a&gt; in the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up your machine
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;gcloud&lt;/code&gt; CLI is a useful tool that is available online in the &lt;a href="https://shell.cloud.google.com/?show=terminal" rel="noopener noreferrer"&gt;Cloud Shell terminal&lt;/a&gt;, but since most developers like to work with editors on their own machines, I highly encourage you to install the Google Cloud CLI on your own machine as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up a cloud project
&lt;/h2&gt;

&lt;p&gt;A cloud project refers to the set of cloud infrastructure (compute, databases and other storage, load balancers, etc.), resources (container images, secrets, static assets, etc.), and security controls for your application (or collection of related applications).&lt;/p&gt;

&lt;p&gt;When you create a new cloud project, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in at the terminal&lt;/li&gt;
&lt;li&gt;Create a project&lt;/li&gt;
&lt;li&gt;Link the project to a billing account&lt;/li&gt;
&lt;li&gt;Delete the project when finished&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Log in at the terminal
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud auth login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Create a GCP project
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;If you already have a specific GCP project to use, you can skip this.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you're logged in, you can create a new GCP project using the gcloud projects create command.&lt;/p&gt;

&lt;p&gt;This is the command to create a project called project-foo:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud projects create project-foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There are a few things to keep in mind when choosing a project ID. The project ID must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be globally unique within Google Cloud.&lt;/li&gt;
&lt;li&gt;Be 6 to 30 characters long.&lt;/li&gt;
&lt;li&gt;Only contain lowercase letters, numbers, and hyphens.&lt;/li&gt;
&lt;li&gt;Start with a letter and must not end with a hyphen.&lt;/li&gt;
&lt;li&gt;Not be or have ever been in use.&lt;/li&gt;
&lt;li&gt;Not contain restricted strings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See the &lt;a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects#before_you_begin" rel="noopener noreferrer"&gt;Before you begin section&lt;/a&gt; for Google Cloud's Resource Manager if you want to see more details and further restrictions. &lt;/p&gt;

&lt;h3&gt;
  
  
  Link the project to a billing account
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're using an existing project that already has billing linked to it, you can skip this.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you've created the project, you must link it to a billing account. You can find your billing account ID on &lt;a href="https://console.cloud.google.com/billing" rel="noopener noreferrer"&gt;your billing accounts page&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud billing projects link my-amazing-project --billing-account 0X0X0X-0X0X0X-0X0X0X
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Delete the project when no longer needed
&lt;/h3&gt;

&lt;p&gt;If you're creating a test project, you'll want to remember to delete it when you're finished. Deleting a project will terminate or release resources associated with it so they no longer incur any potential usage fees.&lt;/p&gt;

&lt;p&gt;Using the example project (&lt;code&gt;project-foo&lt;/code&gt;) created previously:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud projects delete project-foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Caution!&lt;/p&gt;

&lt;p&gt;It should go without saying that you want to be really sure you want to delete a project. A deleted project immediately becomes unusable, although it can be restored within a 30-day recovery period. See &lt;a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects#restoring_a_project" rel="noopener noreferrer"&gt;Restoring a project&lt;/a&gt; if you need to stop the delete process.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;In the next article, get started generating the TypeScript boilerplate and deploy to Cloud Run.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create and deploy an Express API to Cloud Run</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Wed, 04 Jan 2023 19:24:57 +0000</pubDate>
      <link>https://dev.to/subfuzion/create-and-deploy-an-express-api-to-cloud-run-68b</link>
      <guid>https://dev.to/subfuzion/create-and-deploy-an-express-api-to-cloud-run-68b</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In this article, I'm going to walk you through quickly generating either a basic starter Express API app or a simple example Express API app and deploying it to &lt;a href="https://cloud.google.com/run" rel="noopener noreferrer"&gt;Cloud Run&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;See the prerequisites for using &lt;code&gt;run&lt;/code&gt;, a lightweight CLI for creating and deploying Cloud Run apps &lt;a href="https://github.com/subfuzion/run#prerequisites" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the app
&lt;/h2&gt;

&lt;p&gt;Choose either &lt;code&gt;express-api&lt;/code&gt; or &lt;code&gt;example-express-api&lt;/code&gt; when asked to choose a project template. The example version demonstrates using various Express methods for a mock database.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

run create


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Selecting a template&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltc629fhdxk8h3bldzk4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltc629fhdxk8h3bldzk4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;When finished&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvl97ocnlc4wqs8s4gecf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvl97ocnlc4wqs8s4gecf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can run the app locally, if you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy the app
&lt;/h2&gt;

&lt;p&gt;To deploy to Cloud Run, enter:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

run deploy


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since this is the first deployment, you'll be presented with a series of prompts. Your settings will be saved to a a local configuration file (&lt;code&gt;run.yaml&lt;/code&gt;).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: In the current version of &lt;code&gt;run&lt;/code&gt;, only the new project option works.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Test the app
&lt;/h2&gt;

&lt;p&gt;When the deployment is finished, the &lt;code&gt;run&lt;/code&gt; will print the URL for accessing the app.&lt;/p&gt;

&lt;p&gt;If you chose &lt;code&gt;example-express-api&lt;/code&gt;, the README includes instructions about testing the API using &lt;code&gt;curl&lt;/code&gt; commands in a test script.&lt;/p&gt;

&lt;h2&gt;
  
  
  View app logs
&lt;/h2&gt;

&lt;p&gt;To get the link to view the logs web page, enter:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

run logs


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;run&lt;/code&gt; command to delete the project when finished is not yet implemented. For now, use &lt;code&gt;gcloud&lt;/code&gt; to delete the project using its ID (if you forget the project ID, it's stored in &lt;code&gt;run.yaml&lt;/code&gt;).&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

gcloud projects delete PROJECT


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you run into any problems, check to see if there is an issue &lt;a href="https://github.com/subfuzion/run/issues" rel="noopener noreferrer"&gt;here&lt;/a&gt; and, if not, please create one.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;I provide background on &lt;code&gt;run&lt;/code&gt; in my &lt;a href="https://dev.to/subfuzion/streamlining-gcloud-with-a-custom-cli-for-serverless-javascript-developers-2oba"&gt;last article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you prefer to use &lt;code&gt;gcloud&lt;/code&gt;, see &lt;a href="https://dev.to/subfuzion/getting-started-with-the-google-cloud-cli-interactive-shell-for-serverless-developers-45l"&gt;this article&lt;/a&gt; if you need help getting started. You'll still use &lt;code&gt;run&lt;/code&gt; to create the app from a template.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>node</category>
      <category>api</category>
      <category>websockets</category>
    </item>
    <item>
      <title>Streamlining gcloud with a custom CLI for serverless JavaScript developers</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Wed, 04 Jan 2023 17:33:17 +0000</pubDate>
      <link>https://dev.to/subfuzion/streamlining-gcloud-with-a-custom-cli-for-serverless-javascript-developers-2oba</link>
      <guid>https://dev.to/subfuzion/streamlining-gcloud-with-a-custom-cli-for-serverless-javascript-developers-2oba</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In my &lt;a href="https://dev.to/subfuzion/getting-started-with-the-google-cloud-cli-interactive-shell-for-serverless-developers-45l"&gt;previous article&lt;/a&gt;, I walked through using the Google Cloud CLI interactive shell for deploying serverless apps to Cloud Run.&lt;/p&gt;

&lt;p&gt;As noted, &lt;code&gt;gcloud&lt;/code&gt; provides comprehensive commands, but using it involves fairly detailed knowledge of a somewhat daunting number of steps that must be followed to set up project resources and deploy an app.&lt;/p&gt;

&lt;p&gt;To simplify the experience for JavaScript developers, I created a lightweight CLI, called &lt;code&gt;run&lt;/code&gt;, that streamlines those steps using a simple configuration file (&lt;code&gt;run.yaml&lt;/code&gt;) to handle all the details. When you deploy, &lt;code&gt;run&lt;/code&gt; will prompt for any missing configuration settings and save them for subsequent deployments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpeuwhe7b0yy7fxwvk5iu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpeuwhe7b0yy7fxwvk5iu.png" alt="Image description" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition, the &lt;code&gt;run&lt;/code&gt; CLI can also generate starter projects and examples to help you get up and running even faster.&lt;/p&gt;

&lt;p&gt;To create and deploy an application, you run the following commands:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

run login
run new
run deploy


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This what using &lt;code&gt;run&lt;/code&gt; looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnio45p8cj9modzfthes7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnio45p8cj9modzfthes7.png" alt="Image description" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I plan to add more templates, examples, and support for integrations with other Google Cloud services.&lt;/p&gt;

&lt;p&gt;Keep in mind that &lt;code&gt;run&lt;/code&gt; is not a replacement for everything that &lt;code&gt;gcloud&lt;/code&gt; can do. It's primary goal is only to make it easier for JavaScript developers to get up and running on Cloud Run.&lt;/p&gt;

&lt;p&gt;Install it from &lt;a href="https://www.npmjs.com/package/@subfuzion/run" rel="noopener noreferrer"&gt;npm&lt;/a&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install -g @subfuzion/run

# or

npx @subfuzion/run


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;See the &lt;a href="https://github.com/subfuzion/run" rel="noopener noreferrer"&gt;repo&lt;/a&gt; for more details.&lt;/p&gt;

&lt;p&gt;Give &lt;code&gt;run&lt;/code&gt; a try and let me know what you think.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting started with the Google Cloud CLI interactive shell for serverless JavaScript developers</title>
      <dc:creator>Tony Pujals</dc:creator>
      <pubDate>Mon, 31 Oct 2022 14:00:00 +0000</pubDate>
      <link>https://dev.to/subfuzion/getting-started-with-the-google-cloud-cli-interactive-shell-for-serverless-developers-45l</link>
      <guid>https://dev.to/subfuzion/getting-started-with-the-google-cloud-cli-interactive-shell-for-serverless-developers-45l</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Aspiring JavaScript wizards might think conjuring serverless apps on Google Cloud with the CLI is an arcane art. But becoming an adept is easier than you think and you don't even need to attend a School of Witchcraft and Wizardry.&lt;/p&gt;

&lt;p&gt;In this article, I'm going to show you what you need to know to deploy a single Cloud Run app from the command line – the stuff you'll need to do once, stuff you need to do for each project, and stuff you'll need to do for each app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Stuff you need to do once&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign up for a Google Account&lt;/li&gt;
&lt;li&gt;Enable billing&lt;/li&gt;
&lt;li&gt;
Install the Google Cloud CLI

&lt;ul&gt;
&lt;li&gt;Enable gcloud interactive shell&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Stuff you need to do for each project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in&lt;/li&gt;
&lt;li&gt;Create your Google Cloud project&lt;/li&gt;
&lt;li&gt;Link your project to a billing account&lt;/li&gt;
&lt;li&gt;Configure your Google Cloud project&lt;/li&gt;
&lt;li&gt;Enable Google Cloud service APIs&lt;/li&gt;
&lt;li&gt;Create a Docker repo for your apps&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Stuff you need to do for each app&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
Activate your project &lt;/li&gt;
&lt;li&gt;Deploy your app&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Try everything out with a demo&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;What's next?&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;This article will be part of a series on serverless development for JavaScript programmers, but the information here should be helpful for any developer who wants to get up and running with &lt;code&gt;gcloud&lt;/code&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Stuff you need to do once
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Sign up for a Google Account
&lt;/h3&gt;

&lt;p&gt;You can &lt;a href="https://accounts.google.com/SignUp" rel="noopener noreferrer"&gt;sign up here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you have an account, you'll have access to both&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a Free Trial&lt;/li&gt;
&lt;li&gt;a Free Tier&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://cloud.google.com/free/docs/free-cloud-features#free-trial" rel="noopener noreferrer"&gt;Free Trial&lt;/a&gt; provides $300 of Cloud Billing credits to pay for resources for 90 days while you learn about Google Cloud.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://cloud.google.com/free/docs/free-cloud-features#free-tier" rel="noopener noreferrer"&gt;Free Tier&lt;/a&gt; provides access to Google Cloud products for free beyond the Free Trial as long as you stay below the Free Tier &lt;a href="https://cloud.google.com/free/docs/free-cloud-features#free-tier-usage-limits" rel="noopener noreferrer"&gt;limits&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Enable billing
&lt;/h3&gt;

&lt;p&gt;If you're using the Free Trial, &lt;a href="https://support.google.com/cloud/answer/7006543?hl=en_" rel="noopener noreferrer"&gt;Google creates a billing account&lt;/a&gt; for you and credits $300 to your account.&lt;/p&gt;

&lt;p&gt;Once your Free Trial ends, you can continue to use the Free Tier, but you'll still need to enable a &lt;a href="https://console.cloud.google.com/billing" rel="noopener noreferrer"&gt;billing account&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Install the Google Cloud CLI
&lt;/h3&gt;

&lt;p&gt;While you might find that using the Google Cloud online &lt;a href="https://console.cloud.google.com/" rel="noopener noreferrer"&gt;console&lt;/a&gt; or &lt;a href="https://cloud.google.com/shell" rel="noopener noreferrer"&gt;Cloud Shell&lt;/a&gt; environment meets your occasional needs, for maximum developer efficiency you will want to &lt;a href="https://cloud.google.com/sdk/docs/install" rel="noopener noreferrer"&gt;install the Google Cloud CLI&lt;/a&gt; (&lt;code&gt;gcloud&lt;/code&gt;) on your own system where you already have your favorite editor or IDE and git set up.&lt;/p&gt;

&lt;h4&gt;
  
  
  Enable gcloud interactive shell
&lt;/h4&gt;

&lt;p&gt;Once you have downloaded and extracted the archive to &lt;code&gt;google-cloud-sdk&lt;/code&gt; directory and added it to your path, then you can then enable the &lt;a href="https://cloud.google.com/sdk/docs/interactive-gcloud" rel="noopener noreferrer"&gt;gcloud interactive prompt&lt;/a&gt;. This feature is for &lt;code&gt;bash&lt;/code&gt;, so you will either need to start a &lt;code&gt;bash&lt;/code&gt; shell or else use &lt;code&gt;gcloud&lt;/code&gt; without the interactive prompt.  &lt;/p&gt;

&lt;p&gt;This is a beta feature, so to enable it, enter the following command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud components install beta
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1g1i4jn4t2uju0inn4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1g1i4jn4t2uju0inn4v.png" alt="Installing beta components" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The interactive prompt makes it easier to work with &lt;code&gt;gcloud&lt;/code&gt; commands in your shell by providing menus for command completion along with contextual help.&lt;/p&gt;

&lt;p&gt;Enter the following command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud beta interactive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Your shell should look something like this now:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiih04y3a6g1g77nos7oi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiih04y3a6g1g77nos7oi.png" alt="Using the interactive shell" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note the tips provided for command completion.&lt;/p&gt;

&lt;p&gt;I like to use an alias for launching the interactive shell. You can create an alias (like &lt;code&gt;gshell&lt;/code&gt;) with the alias command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias gshell="gcloud beta interactive"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Stuff you need to do for each project
&lt;/h2&gt;

&lt;p&gt;In this context, a project specifically refers to the collection of cloud infrastructure and application resources you will provision and deploy on Google Cloud.&lt;/p&gt;

&lt;p&gt;You can deploy multiple Cloud Run apps (&lt;em&gt;services&lt;/em&gt;) as part of the same project.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Log in
&lt;/h3&gt;

&lt;p&gt;You might have several accounts, or your login has expired, or this is your first login. In any case, you can login with the following command:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud auth login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60ozt2wvpajvlvzk0l4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60ozt2wvpajvlvzk0l4o.png" alt="gcloud auth login" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will open a page using your web browser. Confirm that the page is a link under &lt;a href="https://accounts.google.com/" rel="noopener noreferrer"&gt;https://accounts.google.com/&lt;/a&gt; and authorize the Google Cloud SDK to be able to access your Google account. After that, you can close the page. Back in your shell, you should see confirmation that you've logged in like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpodjeu4fafjy31ucob0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpodjeu4fafjy31ucob0.png" alt="gcloud auth login success" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create your Google Cloud project
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;If you already have a specific Google Cloud project to use, you can skip this section and go on to 3. Link your project to a billing account.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you're logged in, you can create or specify an existing Google Cloud project to use and configure locally.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud projects create my-amazing-demo-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fowi5dg85dojdf4y0zquq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fowi5dg85dojdf4y0zquq.png" alt="gcloud projects create" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: If you're creating a project as part of an organization, you'll need to know the Folder ID that your project should be under. Discussing organization accounts is beyond the scope of this article, but you can learn more &lt;a href="https://cloud.google.com/resource-manager/docs/creating-managing-folders" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The command to create the project has an option for providing the Folder ID: &lt;code&gt;gcloud projects create [PROJECT_ID] --folder [FOLDER_ID]&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3. Link your project to a billing account
&lt;/h3&gt;

&lt;p&gt;Once you've created the project, you must link it to a billing account (see 2. Enable billing). You can find your billing account ID on &lt;a href="https://console.cloud.google.com/billing" rel="noopener noreferrer"&gt;your billing accounts page&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud beta billing projects link my-amazing-demo-1 --billing-account 0X0X0X-0X0X0X-0X0X0X
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqorha9na0wmr1mdup2v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqorha9na0wmr1mdup2v.png" alt="gcloud beta billing projects link" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As you might have noticed in the image above, I have my billing account ID saved in a shell variable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  4. Configure your Google Cloud project
&lt;/h3&gt;

&lt;p&gt;Now you can configure settings for your current project so that you don't need to specify them as options each time you run a &lt;code&gt;gcloud&lt;/code&gt; command.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Although you can set default settings, I highly recommend that you create named, project-specific configurations to make switching between projects easier. I also recommend that you give the configuration the same name as the project to help you remember the association when listing or switching configurations, as shown below.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Common settings for Cloud Run projects shown below include the &lt;strong&gt;project ID&lt;/strong&gt;, &lt;strong&gt;&lt;a href="https://cloud.google.com/run/docs/locations" rel="noopener noreferrer"&gt;run/region&lt;/a&gt;&lt;/strong&gt; you want to deploy your app to, and &lt;strong&gt;artifacts/location&lt;/strong&gt; (same thing as region) for your project's Docker repository (for storing the images for launching Cloud Run service containers for your apps).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud config configurations create my-amazing-demo-1
gcloud config set account YOUR_ACCOUNT_EMAIL
gcloud config set project PROJECT_ID
gcloud config set run/region REGION
gcloud config set artifacts/location REGION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To view your current configuration values:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud config list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To list all of your configurations:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud config configurations list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  5. Enable Google Cloud service APIs
&lt;/h3&gt;

&lt;p&gt;You will need to enable a few common Google Cloud service APIs for your project to be able to build, store, and deploy Cloud Run apps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To build Docker container images for your serverless apps, you need to enable &lt;a href="https://cloud.google.com/build/" rel="noopener noreferrer"&gt;Cloud Build&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;To store the Docker container images you'll need to launch serverless app containers on Cloud Run, you need to enable &lt;a href="https://cloud.google.com/artifact-registry/" rel="noopener noreferrer"&gt;Artifact Registry&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;To launch and scale your serverless app containers, you need to enable &lt;a href="https://cloud.google.com/run/" rel="noopener noreferrer"&gt;Cloud Run&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These services all expose APIs that you will use through &lt;code&gt;gcloud&lt;/code&gt; commands.&lt;/p&gt;

&lt;p&gt;Enter the following commands:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud services enable cloudbuild.googleapis.com
gcloud services enable artifactregistry.googleapis.com
gcloud services enable run.googleapis.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;In addition to these APIs, Google provides many other APIs for hosting your apps (such as Cloud Functions) or for being used programmatically to facilitate building your apps (Memorystore, Pub/Sub, etc.). Take a look at the &lt;a href="https://console.cloud.google.com/apis/library" rel="noopener noreferrer"&gt;API Library&lt;/a&gt; and the &lt;a href="https://developers.google.com/apis-explorer" rel="noopener noreferrer"&gt;API Explorer&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  6. Create a Docker repo for your apps
&lt;/h3&gt;

&lt;p&gt;After the Artifact Registry API has been enabled, you create a project-specific Docker container repository. The benefits of doing this is that your container repository will be in the same physical region as your Cloud Run apps under the same security policies as the rest of your project.&lt;/p&gt;

&lt;p&gt;The following command assumes you'll name your Docker container registry as &lt;code&gt;docker-repo&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud artifacts repositories create docker-repo --repository-format=docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Stuff you need to do for each app
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Activate your project
&lt;/h3&gt;

&lt;p&gt;Confirm that you're using the right project configuration and if not, then activate (switch to) it.&lt;/p&gt;

&lt;p&gt;You can confirm that you're using the right project with either of the following two commands.&lt;/p&gt;

&lt;p&gt;List all configurations and indicate which one is active (&lt;code&gt;IS_ACTIVE&lt;/code&gt; column):&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud config configurations list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;List current settings and tell you the active configuration currently in use:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud config list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If the configuration for the project you want to use is not currently active, then activate it with this command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud config configurations activate PROJECT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;This assumes you're using the convention I recommended previously where your configuration has the same name as your Google Cloud project ID.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The interactive shell displays the active project as well:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffibbd6vhbjl1dlwzx0jf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffibbd6vhbjl1dlwzx0jf.png" alt="displaying the active project" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Deploy your app
&lt;/h3&gt;

&lt;p&gt;At this point you can finally deploy your app with a single command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud run deploy SERVICE_NAME --source=. --allow-unauthenticated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftiendpnwbogx29a3r9d0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftiendpnwbogx29a3r9d0.png" alt="gcloud run deploy" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;--source=.&lt;/code&gt; option tells &lt;code&gt;gcloud&lt;/code&gt; to deploy from the current directory.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;--allow-unauthenticated&lt;/code&gt; option tells &lt;code&gt;gcloud&lt;/code&gt; to make your app URL publicly available when it deploys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try everything out with a demo
&lt;/h2&gt;

&lt;p&gt;First, make sure you've taken care of all the stuff you need to do once.&lt;/p&gt;

&lt;p&gt;Then, using your own shell, take care of the stuff you need to do for each app, as shown in the example below.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Give your project a unique name and choose a region from one of these &lt;a href="https://cloud.google.com/run/docs/locations" rel="noopener noreferrer"&gt;Cloud Run locations&lt;/a&gt;. Remember, you don't pay for anything during the free trial and even after that as long as your usage doesn't exceed the &lt;a href="https://cloud.google.com/run/pricing" rel="noopener noreferrer"&gt;Cloud Run pricing&lt;/a&gt; rather generous quotas (CPU, memory, requests) for the free tier.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Substitute with your own shell variable values
$ BILLING_ACCOUNT=0X0X0X-0X0X0X-0X0X0X
$ ACCOUNT=me@gmail.com
$ PROJECT=cloud-run-hello-app-demo
$ REGION=us-central1
$ SERVICE=hello

$ gcloud auth login
...

$ gcloud projects create $PROJECT
...

$ gcloud beta billing projects link $PROJECT --billing-account $BILLING_ACCOUNT
...

$ gcloud config configurations create $PROJECT
$ gcloud config set account $ACCOUNT
$ gcloud config set project $PROJECT
$ gcloud config set run/region $REGION
$ gcloud config set artifacts/location $REGION
....

$ gcloud services enable cloudbuild.googleapis.com
$ gcloud services enable artifactregistry.googleapis.com
$ gcloud services enable run.googleapis.com
...

$ gcloud artifacts repositories create docker-repo --repository-format=docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now deploy your server code. You can clone this repo for a simple demo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/subfuzion/cloud-run-hello-app-demo" rel="noopener noreferrer"&gt;https://github.com/subfuzion/cloud-run-hello-app-demo&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/subfuzion/cloud-run-hello-app-demo.git
$ cd cloud-run-hello-app-demo

$ gcloud run deploy $SERVICE --source=. --allow-unauthenticated
This command is equivalent to running `gcloud builds submit --pack image=[IMAGE] .` and `gcloud run deploy hello --image [IMAGE]`

Building using Buildpacks and deploying container to Cloud Run service [hello] in project [cloud-run-hello-app-demo] region [us-central1]
✓ Building and deploying new service... Done.
  ✓ Uploading sources...
  ✓ Building Container... Logs are available at https://console.cloud.google.com/cloud-build/builds/d71d846a-782d-4161-bbfa-a3f289ae669a?project=243539805744].
  ✓ Creating Revision...
  ✓ Routing traffic...
  ✓ Setting IAM Policy...
Done.
Service [hello] revision [hello-00001-wek] has been deployed and is serving 100 percent of traffic.
Service URL: https://hello-5maonkvcja-uc.a.run.app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Presto! If all went well, your app is deployed at the Service URL, like shown above. If not, you'll need to investigate using the link to the build log shown instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h9n3g79v6rxbsmvppcu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h9n3g79v6rxbsmvppcu.jpg" alt="journey" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While deploying an app is easy, there's no denying that there's quite a bit of administrative effort involved up front to get to that point. Although we're focused on serverless apps, Google Cloud provides many different services for running your workloads at planet scale along with a robust security model for enforcing enterprise policies that does add complexity even for modest needs.&lt;/p&gt;

&lt;p&gt;In the next article in this series, we're going to show you how you can wrap most of these steps in a Node.js command-line app that you can use for your projects to streamline the effort.&lt;/p&gt;

&lt;p&gt;We'll accomplish this in two stages, first wrapping &lt;code&gt;gcloud&lt;/code&gt; shell commands, and then refactoring to use the Node.js Cloud Client Library to invoke the necessary Google Cloud APIs directly. Once you see how this works, you'll be able to tailor the command-line app to suit your own specific needs as they evolve.&lt;/p&gt;

&lt;p&gt;After that, we're going to continue on our journey as you delve into all kinds of mysterious but wonderfully powerful magic for running your serverless JavaScript full-stack and back-end apps.&lt;/p&gt;

&lt;p&gt;There may be dragons!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F704y6zjof48t4qaz79uw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F704y6zjof48t4qaz79uw.jpg" alt="dragons" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you found this article helpful, give it a like and bookmark it. If you have any questions or suggestions, let me know in the comments. Then give me a follow and get notified when I publish the next article in the series. Stay tuned!&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>serverless</category>
      <category>cli</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
