Getting started with Node and pebl — a free cloud platform!
Tags: pebl, cloud, node, devops
Published: 2023-06-22 22:01:50

Pebl recently released support for Node in [release 0.0.7](https://blog.pebl.io/release-007)!

As part of that we are starting a dedicated series on using Node and pebl which will go into detail about how to utilize all the different cloud capabilities that pebl offers.

But we thought it'd be fun to start off the series with a quick guide that is **actually quick**, and should take 5 minutes!

When you are done you will have a Node project configured with a standard [`http.Server`](https://nodejs.org/api/http.html#class-httpserver) deployed to the cloud and serving live traffic!

## Setup

First create a free account at [pebl.io](https://www.pebl.io/signup). Make sure to claim your free `*.pebl.rocks` subdomain! We will be using this to deploy with in this tutorial.

Then download the pebl CLI, the steps are outlined [in the docs](https://docs.pebl.io/setup).

You also need to have Node and Docker installed on your system.

## Project

Now we're ready to initialize the node project! Create a folder to be the root of our project:

```
$ mkdir quickstart
```

Then place this `package.json` inside the folder (Note that you could also use `npm init` to do this):

```
{
  "name": "node",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "pebl": "0.0.8"
  }
}
```

Then install the `pebl@0.0.8` dependency by running `npm install`

```
$ cd quickstart
$ npm install

added 1 package, and audited 2 packages in 739ms

found 0 vulnerabilities
$
```

## A simple server

Let's create an `index.js` with a simple server that utilizes pebl's [service](https://docs.pebl.io/reference/SDK) functionality:

```js
import * as pebl from 'pebl';
import * as http from 'http';

const requestListener = function (req, res) {
  res.writeHead(200);
  res.end("hello, world!\n");
};
const server = http.createServer(requestListener);

pebl.service(server, "your-domain-here.pebl.rocks")
```

**Here make sure to place your own `pebl.rocks` subdomain!**

## Deploying

Now we are ready to deploy the project.

First run `pebl auth` to authenticate the pebl CLI with your pebl account.

Then run `pebl deploy` at the root of the project!

```
$ pebl deploy
 :: building node project...
 :: containerizing the build...
 :: build success!
 :: uploading...
 :: success!
$
```

Now you can send requests to your deployment with curl:

```
$ curl https://your-domain-here.pebl.rocks
```

Make sure to use `https`, as all pebl deployments get free SSL certificates!

## FAQ

### Can I run this locally?

Yes! One power of pebl is that you can run the same code locally and in the cloud, without any modification. We will go into more details about how to do this, but the short version is: first create a local cluster with `pebl up`, then you can run local workloads with `pebl run` in the project folder.

### Can I use [Express](https://expressjs.com/)?

Yes! In fact you use any server that conforms to [net.Server.listen](https://nodejs.org/api/net.html#serverlisten).

### Can I use my own custom domain with pebl?

We are currently beta testing this feature! If you are interested, fill out this typeform link and we will be in touch: [https://ie0rdzi5b9h.typeform.com/to/V0PJ90un](https://ie0rdzi5b9h.typeform.com/to/V0PJ90un).