DEV Community

Jbee - codehooks.io
Jbee - codehooks.io

Posted on

Hello world! Serverless JavaScript with codehooks.io

Hi JavaScript coders.

We´ve launced a new service for running your JavaScript (ES6) application as a serverless API backend with codehooks.io.
Zero config, built-in NoSQL storage and much more.

Check out the simple Hello world example below.

First install the CLI and login/signup.

$ npm install codehooks -g

$ codehooks login
Enter fullscreen mode Exit fullscreen mode

Create a project with the codehooks create CLI command.

$ codehooks create mybackend

$ cd mybackend
Enter fullscreen mode Exit fullscreen mode

In the mybackend folder, create a index.js file for your JavaScript.

import app from 'codehooks-js'

// create an API GET endpoint /hello
app.get('/hello', async (req, res) => {
  console.log("Look mum I'm running in the cloud");
  res.json({"message": "Hello world!"});
});

export default app.init();
Enter fullscreen mode Exit fullscreen mode

Install your NPM dependencies.

npm i codehooks-js
Enter fullscreen mode Exit fullscreen mode

Deploy with the CLI.

$ codehooks deploy
Enter fullscreen mode Exit fullscreen mode

Test the new API with curl (example API key is fake).

curl https://mybackend-x23a.api.codehooks.io/dev/hello -H 'x-apikey: 6e111ea6-6b3a-412d-8f6b-061c816c67c8'
Enter fullscreen mode Exit fullscreen mode

Example output from curl.

{"message": "Hello world!"}
Enter fullscreen mode Exit fullscreen mode

Happy coding and deploying :)

Top comments (0)