Skip to content

bennyschmidt/node-service-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project was bootstraped with node-service-core.

Full Stack Example

Create a new service

In /index.js:

const Services = {
  "Example": {} // add your new service
};

In /src/services/example/index.js:

const { http } = require('node-service-library');

// Import your API endpoints
const { hello } = require('./api');

// Bind them to HTTP method handlers (declarative)
module.exports = http({
  GET: {
    hello
  },
  POST: {},
  PUT: {},
  DELETE: {}
});

In /src/services/example/api/hello/index.js:

// Implement the new API response
module.exports = () => ({ 
  message: 'Hello world :)' 
});

Create a new app

In /index.js:

const Apps = [
  "/",
  "mycoolapp" // Add your new front-end app
];

In /src/apps/mycoolapp/index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>My Cool App</title>
  </head>
  <body>
    <script>
      (async () => {
        const response = await fetch('/example/hello');

        if (response?.ok) {
          const result = await response.json();
           
          // Prints "Hello world :)" to the DOM
          document.write(result.message);
        }
      })();
    </script>
  </body>
</html>

Add as many new services, APIs, and front-end applications as you need.

For serverless setups, functions in the api/ directory of any service are already modularized and can be moved as-is to AWS Lambda, Vercel serverless, etc.

Node Service Library

About

A Node.js boilerplate for running multiple services & apps.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published