DEV Community

Jbee - codehooks.io
Jbee - codehooks.io

Posted on

3 1

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 :)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️