Second-ever hackathon experience
Tags: hackathon, nyc, javascript, learning
Published: 2019-03-16 01:44:02

---
title: Second-ever hackathon experience
published: true
description: Learning points from my second hackathon experience
tags: hackathon, nyc, javascript, learning
---

## Took part in a hackathon!
Over the last weekend, I took part in a hackathon called HackRU at Rugters University, over at New Jersey. 

At the beginning, I was really not looking forward to it. I had a really bad week emotionally (some minor fuck ups at work, being careless etc), and wanted nothing more than to just curl up in a ball and sleep off the weekend. Even though I learnt a lot through work like get used to ES6 syntax which i've known for quite a while but wasn't actively using in my projects (it has been around 2 months since i moved here to do an internship ... shall elaborate more in a separate post), i felt like i had a long way to go as a front end dev and felt slightly burnt out at this juncture. =( 

Plus, the commute was pretty long (1 hour subway ride to Penn station, and 1 hour train ride to the venue). But I am so glad my friends encouraged me to go for it anyway (since we had already RSVP-ed a few weeks back and I was on the confirmed list of attendees). 

Unfortunately (or expectedly) I ended up being the only one coding, cos I knowingly went to the hackathon with my friends who didn’t know how to code and wanted to just experience it. 

I was pondering if i should stick to something familiar like build a mobile app, use Google Maps API etc, or try to learn something different. Thanks to my friends, I ended up building a Telegram bot with node.js, using a wrapper for API calls that i found on GitHub called `botgram`. A few hours in and I was regretting my decision because the wrapper uses a pretty old version of the Telegram API.  The syntax was pretty easy to use though. 

I also used `request` and ofc `dotenv`.  

## .env

I was pretty curious about `.env` as I was wondering how in the world do i use my env variables without directly passing in from the command line. 

I was reading tutorials furiously at that point and they were telling me to pass in my bot token through the command line, which isn’t wrong per se.. but I needed something that would be able to do so by itself because I wanted to deploy on to a server online and just run a command like `node index.js`. 

Tbh it was the first time I was more conscious of `.env` or environment file outside of work context.  I also found out it was quite easy to setup the `.env` file by just : 
`TELEGRAM_BOT_TOKEN=TOKENHERE`. Then I need to use `dotenv.config()`
and then destructure them to use it as such: `const { TELEGRAM_BOT_TOKEN } = process.env;`

Also, I had to remember to add it into my gitignore file. Which I conveniently forgot to do so for stuff like node_modules etc too :( 

This is a way more informative read about this topic: [Node.js Everywhere with Environment Variables! – Node.js Collection – Medium](https://medium.com/the-node-js-collection/making-your-node-js-work-everywhere-with-environment-variables-2da8cdf6e786)

## Deploying live to Google Cloud
I wanted to try other services such as Now, since this tutorial recommends me to do so: [Part 2 How to deploy a Telegram Bot using Now (Building a Bookmark Manager Bot series)](https://itnext.io/part-2-deploying-a-telegram-bot-using-now-building-a-bookmark-manager-bot-series-9304104a64ae). However I think some changes in their services meant that I had to be constantly making requests [You tried to create a Now 1.0 deployment. Please use Now 2.0 instead · Issue #1843 · zeit/now-cli · GitHub](https://github.com/zeit/now-cli/issues/1843) and there was no way to use Now 1.0 which was what the tutorials recommended. It was super frustrating because within a span of a few months, the recommendation became 'obsolete'... and i spent hours trying to figure out if there's a workaround but nope. 

After trying several other services, I tried out Google Cloud. And it worked like a charm (well, iirc it ‘stops’ after 5 minutes of inactivity.. but at least that’s better off).

I just followed the instructions to setup via the Documentation for Google Cloud SDK: 
[Google Cloud SDK documentation  |  Cloud SDK       |  Google Cloud](https://cloud.google.com/sdk/docs/#install_the_latest_cloud_tools_version_cloudsdk_current_version)

1. Download SDK
2. Place unzipped SDK contents in your root directory for the app you want to deploy
3. run command in correct directory: `./google-cloud-sdk/install.sh`

After installing the SDK, install the Command Line Tool on your machine. 

[Quickstart: Using the gcloud Command-Line Tool  |  Cloud Functions Documentation       |  Google Cloud](https://cloud.google.com/functions/docs/quickstart#functions-update-install-gcloud-node8)

Just follow steps on this website. 

Also ensure before deploying app, you need to set up a `app.yaml` file where you state your runtime env: Example for nodejs
```
runtime: nodejs10
```

## Conclude
Unfortunately, this project didn't win any prizes haha. But I really learnt quite a bunch of stuff during the hackathon, and it brought back fond memories of me coding overnight for school projects. I'm glad to have tried out something new, and I was quite amazed by how much i learnt in just a day. I felt motivated/recharged to go back to work to continue coding and learn more things! 

*To improve on my project… *
- use async await (unfortunately i couldn’t get the hang of it during the hackathon itself). 
- Implement Dialogflow for sentiment analysis 
- Just use Telegram API direct!