• Packaging NodeJS scripts into a Binary



    Hey Node devs, jealous of Go devs for being able to create single binaries without any dependencies?
    Now you can do it too! With pkg - a binary compiler for NodeJS!

    pkg - from NodeJS to binary

    I recently developed a NodeJS script that automatically consumes SQS messages when an EC2 instance is initiated.
    My most major issue has been the dependencies - NodeJS installation was often slow, and would sometimes fail or timeout.
    On top of that, I had to also install the AWS SDK in order to get the SQS messages.
    The entire thing was too much of a delay for my User Data script to handle.

    Side Note: User Data is a script that executes when an EC2 instance is initialized. Very useful for pulling Docker images or running init scripts.

    After an evening of debugging, I started thinking - this would be a whole lot easier with Go, as I would just have a single binary file and zero dependencies to install.
    The issue was that converting my entire script to Go would've required much more time, and would likely create new issues (as AWS SDK varies between the languages, not to mention I'm much more experienced with NodeJS compared to Go).
    I then thought that within the infinite universe of NPM there must be a tool that packages binaries out of NodeJS scripts, or at least somehow bundles the NodeJS runtime together with my script.

    pkg to the rescue!

    pkg allows you to bundle your NodeJS scripts into a single binary.
    No more dependencies, no more node_modules/, package.json, npm install...
    Simply download the single executable and... well... Execute!

    I have successfully tested the following with pkg:
    • NodeJS environment (obviously) - includes Node8, Node6, and Node4 (9 is not supported yet)
    • Operating System - includes linux, mac, and windows
    • NPM Libraries (aws-sdk in my case) - works without any configuration
    • Environment Variables - works without any configuration
    • Spawning Child Processes - works without any configuration
    • Async/Await - works without any configuration

    Install pkg

    npm install -g pkg
    Tip: it also works if you install it locally, you would simply have to run:
    ./node_modules/.bin/pkg
    instead of just pkg

    Run pkg

    pkg --targets node8-linux server.js -o server-linux
    The command above simply bundles server.js into a linux binary named server-linux



    Until next time!
  • 5 super useful Google Chrome tricks



    I have been using Chrome for many years now, mostly not really thinking of it as a browser but rather just a thin layer between me and the WWW.
    Today I realized something pretty interesting - you can select multiple tabs by holding down the CTRL key and clicking with your mouse!
    The selected tabs can be moved to another window, or moved around other existing tabs. Until now I have been moving them one-by-one like some animal!

    I decided to make a list of 5 lesser known Chrome tricks (ok except CTRL + SHIFT + T).

    Create App shortcuts

    Apparently there's a mode on Chrome called "App mode", which is just a very light window without any extra toolbars, designed to only display a web-app's content. On Menu -> Tools / More tools -> Create application shortcuts... / Create shortcut... you will find an option to create shortcuts for such web-apps. Now on Windows the icon will show up on your Desktop, and on Linux it'll be under your main application menu -> Chrome Apps (not sure about Mac, likely to be either or).
    In case you want to use the command line, there's an options for that too:
    google-chrome --app=www.google.com

    Play the Dinosaur T-Rex game, even when you're online!

    By going to chrome://dino/ you can play the T-Rex Game. No longer do you have to wait for your provider to have a technical issue to enjoy this game :)

    Understand how Omnibox works

    By going to chrome://omnibox/ , you can see exactly the results that Omnibox generates and how they were arrived at. This is super cool when Omnibox sometimes gives you odd results, like when you're typing "Cale" (for Google Calendar) and it gives you a Google search for "Cale" instead of "calendar.google.com".

    Select multiple tabs

    As mentioned before you can use CTRL + click to select multiple tabs on Chrome. Multi-tabs selection gives you a quick way to send them to another window, or move them between your existing tabs.
    Bonus tip: You can select entire ranges of tabs with SHIFT + click, just like in a file browser!

    Reopen closed tab

    By now I imagine most of you know about CTRL + SHIFT + T. Just in case some of you don't, it's a magical combination of keys that lets you reopen a tab you just accidentally closed.
    It's a lifesaver, and I admit to use it at least once a day.
  • 3 Startups from Zurich, London and San-Francisco compared



    This is a story of 3 startups, starting in 3 different ecosystems, with similar solutions for Invoice Financing.
    Here we will be looking into their funding rounds to learn about the differences between the startup ecosystems of Zurich, London, and San Francisco.
    First of all:

    What's Invoice Financing?

    Scenario: You're a web developer, and you get paid 30 days after the invoice was sent. Until then, you need to pay your rent/business expenses, what do you do? A bank loan is the traditional solution (but it takes time). Invoice financing is a modern solution to this, providers give you the money in return of some interest, and you pay them back within several weeks/months.

    The companies we're looking into

    • Advanon - A Zurich based startup. Total Funding: 13.92M USD (13.6M CHF)
    • MarketInvoice - A London based startup. Total Funding: 58.26M USD (45.8M GBP)
    • Fundbox - A San Francisco based startup. Total Funding: 107.5 USD
    When looking at the numbers, this comparison symbolizes the stark difference between the ecosystems.

    Advanon, being a Swiss startup, has only gone through 2 rounds in the last 4 years. Noticebly, having a pretty large Series A round of 13.5M CHF. This is a very solid indication of the Swiss tech market as a whole, funding rounds aren't as quick, but they are definitely enough for a lean burn rate (keeping in mind the local salary ranges) and steady growth.

  • Multiple Deployments with Terraform Workspaces

    In recent months, I've been working more and more with Terraform, deploying to multiple cloud providers and even combining it with Serverless projects (more on that on the next post).

  • How to install global NPM packages locally

    Too many NPM libraries are demanding to be globally installed, to name a few:
    npm install -g serverless
    npm install -g terraform
    npm install -g mocha
    While it's sometimes very useful to have some of these components globally available,
    in many cases you only need them for 1-2 projects.
    In some cases, you might not have permissions to install packages globally.

    The reality is, you don't need to install them globally at all!

    Installing a global NPM package locally

    Let's take Serverless as an example. Let's say we want to deploy an existing project, but we don't have Serverless installed on our system.
    First we install the package locally:
    npm install serverless
    Then, on our node_modules/ directory, there's a hidden .bin/ directory, where the serverless binary is located.
    So from the main project directory, we simply run:
    ./node_modules/.bin/serverless deploy -v
    Now if you want to make it a bit more snappy, you could add a shortcut (i.e. symbolic link) to the binary:
    ln -s node_modules/.bin/serverless serverless
    And from now on simply run any serverless command like so:
    ./serverless deploy -v
    On rare occasions, some packages' binaries are not under node_modules/.bin/ but somewhere inside the package's directory, such as node_modules/serverless/bin/.

    So far I've been using locally installed packages for Serverless, SailsJS, Mocha, Terraform, and a few others as well.

    On the next post, we'll try playing around with Serverless and S3, stay tuned!