Byte-Sized Tech Tips Round-Up: Week 3
Tags: node, javascript, microservices
Published: 2020-10-23 20:32:22

> From
> {% user blumareks %}

When I have started to develop a chatbot for Discord, I realized that everybody is using Node installed in their own environments. I was aiming at running a bot right away in the cloud. Instead of running your bot "natively" in your system using `node`, I created a Docker container that handles it all for me.

### `index.js`

```javascript
const Discord = require('discord.js');
const client = new Discord.Client();
const Token = process.env.token;
client.on('ready', () => {  
   console.log('Logged in as ${client.user.tag}!');
});
client.on('message', msg => {  if (msg.content === 'ping')
{
     msg.reply('Pong!');  
}});
client.login(Token);
```

### `package.json`

```json
{
"dependencies": {
    "discord.js": "^12.3.1"
  }
}
```

### `Dockerfile`

```Dockerfile
FROM node:10
ENV NODE_CONTAINER_VERSION=1.0.0
# Create directory for application
WORKDIR /data/bot-app
# Install dependencies
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "node", "index.js" ]
```

Now you can build your image (use your Docker id here - and mind the trailing dot):

```bash
docker build -t <YOUR_DOCKER_ID>/node-container .
```

And to start your Docker container with the Discord bot (add in your Discord token):

```
docker run -e token="<YOUR_TOKEN>" -d <YOUR_DOCKER_ID>/node-container
```

Now you can ping your bot! 🤖

![discord](https://dev-to-uploads.s3.amazonaws.com/i/qo188unw8jn50q8kcyha.png)

Read a long version of this post [in my blog](https://medium.com/voice-tech-podcast/yeah-a-discord-ai-powered-bot-baby-d9cb73b4775d?source=friends_link&sk=5fd7e544211b3f64b8e5ca476dd547c9)

## Javascript: `in` vs `of`

> From [Nigel](https://www.linkedin.com/in/pnigelbrown/)

This week I learned about a neat little trick when iterating through arrays in javascript. The important of `in` which gives you the position in the array, and `of` which gives you the value of the element in the array. Fun!

```javascript
let myArray = ["cat", "dog", "mouse"]

for (let val in myArray) {
    console.log(val) // 0, 1, 2
}

for (let val of myArray) {
    console.log(val) // "cat", "dog", "mouse"
}
```

Shout out to [Nick Bourdakos](https://dev.to/bourdakos1) for showing me this one.

## Bee Travels

> From
> {% user poojamakes %} 

We're hosting a 6-part online series on microservices. If you are new to microservices or have been using microservices for some time – you will get high-quality developer education. Register for all six session below. The replay of each session will be available at the same link.

![beetravels-session](https://dev-to-uploads.s3.amazonaws.com/i/zi853kk50j9y2yqtt15i.png)

* [Part 1: Designing Mircoservices](https://www.crowdcast.io/e/beetravels_part1) (October 20, 2020)
* [Part 2: Deploying Mircoservices](https://www.crowdcast.io/e/beetravels_part2) (October 27, 2020)
* [Part 3: Debugging Mircoservices](https://www.crowdcast.io/e/beetravels_part3) (November 5, 2020)
* [Part 4: Developing Microservices with Node.js](https://www.crowdcast.io/e/beetravels_part4) (November 10, 2020)
* [Part 5: Virtual Hands On Building Microservices Lab](https://www.crowdcast.io/e/beetravels_part5) (November 17, 2020)
* [Part 6: Data Handling in Mircoservices](https://www.crowdcast.io/e/beetravels_part6) (November 24, 2020)