DEV Community

Ravaka Razafimanantsoa
Ravaka Razafimanantsoa

Posted on

Some pitfalls on Google Cloud Engine with NodeJS

I have been playing around making some Typescript/NodeJS based API as a side project and this weekend I decided to deploy it on Google Cloud Engine Standard for NodeJS thinking it would be fast and easy. How wrong I was.

The main interests in using GCE Standard are that it is entirely managed so no maintenance to do and it also scales from 0 so no traffic, nothing to pay. The bad side of is that you have poor control on the machine running the application, commands like ls, cd or even npm are not even available.
When deploying the application, Google calls npm install for you in production mode (so not installing devDependencies) to get the correct dependencies for the architecture you will be running on. This is where things turned bad for me.

My application is quite standard, written in Typescript but with a dependency hosted on a private repository on Gitlab. Having used git+ssh to develop locally, I tried to deploy this way. It does not work. There is no way to provide the credentials needed by npm to access the code with ssh, even the environment variable GIT_SSH_COMMAND does not work (seems to be ignored). Heck, even npm install does not exist, the logs are talking about npm_install! I have been trying to look for another solution for 3 days and nothing worked, with git+ssh.

I then tried to go the git+https road with tokens embedded in the URL, well that was the road to go, not fan of adding credentials for read only access in package.json but could not find a better way.

Ok, now, deployment is successful! Calling a random method from my API, something is wrong... I am missing the dependency I managed to install after many days of trial and error. Great! The thing is that my dependency is written in Typescript too, I transpile it with tsc in the npm script preinstall which seems to be ignored. Bummed, I went the dirty way by commiting the dist folder and now it works.

To make things cleaner, I am thinking of making a tarball with the transpiled code using GitlabCI and make it available as a build artefact. Still trying to find another way.

The road was long and I could not find documentation about it (only things about having a private repository on npm so paying 7$/month/user for this feature). In the end, I still managed to do what I wanted and deploy my application on Google Cloud Engine Standard for NodeJS. Hope these notes will help someone.

Top comments (0)