DEV Community

Cover image for Getting started with Node and pebl — a free cloud platform!
Jin Lee for pebl

Posted on

Getting started with Node and pebl — a free cloud platform!

Pebl recently released support for Node in release 0.0.7!

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 deployed to the cloud and serving live traffic!

Setup

First create a free account at pebl.io. 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.

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
Enter fullscreen mode Exit fullscreen mode

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"
  }
}
Enter fullscreen mode Exit fullscreen mode

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
$
Enter fullscreen mode Exit fullscreen mode

A simple server

Let's create an index.js with a simple server that utilizes pebl's service functionality:

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")
Enter fullscreen mode Exit fullscreen mode

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!
$
Enter fullscreen mode Exit fullscreen mode

Now you can send requests to your deployment with curl:

$ curl https://your-domain-here.pebl.rocks
Enter fullscreen mode Exit fullscreen mode

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?

Yes! In fact you use any server that conforms to net.Server.listen.

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.

Top comments (0)