Deploy the tiniest nodejs server in repl.it
Tags: todayilearned, javascript, node
Published: 2021-02-12 23:44:17

---
title: Deploy the tiniest nodejs server in repl.it
published: true
description: deploying a web server with minimal amount of boilerplate in repl.it
tags: #todayilearned #javascript #node
//cover_image: https://direct_url_to_image.jpg
---

> Pueden leer la versión en español [aquí](https://dev.to/vonheikemen/despliega-un-servidor-nodejs-super-ligero-en-repl-it-3h2c).

I recently learned that [repl.it](https://repl.it) has support for web servers. I know, I'm late to the party. In my defense I've never needed (or wanted) one. Anyway, we are going to learn how we can deploy a microservice-ish type of deal using repl.it.

## The boilerplate

Let's say you created a fresh `node` repl.it. By default you'll have an `index.js` file created and ready to go. In that file we are going to place the most simple code we can think of to test our server. Here it is.

```js
module.exports = async function(request, response) {
  return 'Hello!';
}
```

Now we need something else.

## The server

The wonderful team of vercel has exactly what we need to run this thing, it is package called [micro](https://github.com/vercel/micro). You can install it using the menu on the side bar. Click on the little icon that looks like a box, and then search for micro. Select the package and click the plus sign.

## The config

We have the business logic of our server ready, we have the server itself, now we need to tell repl.it how to run it. 

Create a new file called `.replit` with the following content.

```toml
run = 'node_modules/.bin/micro -l tcp://0.0.0.0:3000 index.js'
```

That file, specifically the `run` property, can tell repl.it what command we want to execute when we press the big button that says "run".

And that commands what it does is this: First reach for the micro executable (which is the one that actually does the setup for the server), tell it to listen to this url `tcp://0.0.0.0:3000` and that `index.js` is the entrypoint for our server.

## The Grand Finale

Now all you have to do is press that "run" button and you're done.

You can check out a working example here: [repl - FoolishBurdensomeLine](https://repl.it/@VonHeikemen/FoolishBurdensomeLine). And the wonderful content is serving is here: [https://FoolishBurdensomeLine.vonheikemen.repl.co](https://FoolishBurdensomeLine.vonheikemen.repl.co)

## Conclusion

Congrats! You have created a web server!

Do note that `micro` really does honor its name. It really doesn't do much. All it does is give you the request so you can return a response. If you need routing, authentication or handle cookies or whatever, search in this repo: [Awesome micro](https://github.com/amio/awesome-micro). If you find yourself wanting lots of those packages consider using a full-featured framework instead.

## Sources
* [repls: Configuring the Run Button](https://docs.repl.it/repls/dot-replit)
* [repls: Deploying HTTP Servers](https://docs.repl.it/repls/http-servers)
* [micro: cli usage](https://github.com/vercel/micro#command-line)

---

Thank you for reading. If you find this article useful and want to support my efforts, [buy me a coffee ☕](https://www.buymeacoffee.com/vonheikemen).

[![buy me a coffee](https://res.cloudinary.com/vonheikemen/image/upload/v1618466522/buy-me-coffee_ah0uzh.png)](https://www.buymeacoffee.com/vonheikemen)