Skip to content

Commit 938b3ab

Browse files
author
Shreyas Nayak
committed
Readme file update
1 parent 15a2cc9 commit 938b3ab

1 file changed

Lines changed: 58 additions & 42 deletions

File tree

README.md

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,102 @@
11
# NodeJS-FAAS
2-
This project aims to achieve something similar to Function as a Service (FaaS) without the overhead of Kubernetes, with extremely low infrastructure requirements.
32

4-
# Why NodeJS-FAAS? Why not any other FaaS?
5-
In today's era, event-driven microservice-based architecture is becoming increasingly popular. Using FaaS, you can trigger any code based on events. However, when you host FaaS in a Kubernetes cluster, you also have to consider the cost per function. NodeJS-FaaS is not intended to replace options such as OpenFaaS. Instead, NodeJS-FaaS offers an extremely lightweight lambda function solution.
3+
This project aims to provide a Function as a Service (FaaS) solution with minimal infrastructure requirements, avoiding the overhead of Kubernetes.
64

7-
# How does it work?
8-
NodeJS-FAAS utilizes the built-in Node.js VM module to execute the code.
5+
## Why Choose NodeJS-FAAS?
6+
7+
In the modern era, event-driven, microservice-based architecture is gaining popularity. FaaS allows you to trigger code execution based on events. However, hosting FaaS on a Kubernetes cluster can be costly. NodeJS-FAAS offers a lightweight alternative, providing an efficient lambda function solution without the need for Kubernetes. It is not intended to replace solutions like OpenFaaS but to offer a simpler, more resource-efficient option.
8+
9+
## How It Works
10+
11+
NodeJS-FAAS uses the built-in Node.js VM module to execute code.
12+
13+
## Setup Instructions
914

10-
# How to set up
1115
You can set up NodeJS-FAAS using Docker or Containerd.
1216

13-
Pull using Docker:
17+
### Using Docker
1418

15-
```
16-
docker pull shreyasnayak21/nodejs-faas:1.1.0
19+
To pull the Docker image:
20+
21+
```sh
22+
docker pull shreyasnayak21/nodejs-faas:1.2.0
1723
```
1824

19-
Run using Docker:
25+
To run the Docker container:
2026

21-
```
22-
docker run -p 9256:9256 shreyasnayak21/nodejs-faas:1.1.0
27+
```sh
28+
docker run -d -p 9256:9256 shreyasnayak21/nodejs-faas:1.2.0 --env JWT_KEY=QX2A0p84VmmLF3NYz3uHPx1hLuhT2U2K
2329
```
2430

25-
Pull using Containerd:
31+
### Using Containerd
2632

27-
```
28-
nerdctl pull shreyasnayak21/nodejs-faas:1.1.0
33+
To pull the image with Containerd:
34+
35+
```sh
36+
nerdctl pull shreyasnayak21/nodejs-faas:1.2.0
2937
```
3038

31-
Run using Containerd:
39+
To run the container with Containerd:
3240

33-
```
34-
nerdctl run -p 9256:9256 shreyasnayak21/nodejs-faas:1.1.0
41+
```sh
42+
nerdctl run -d -p 9256:9256 shreyasnayak21/nodejs-faas:1.2.0 --env JWT_KEY=QX2A0p84VmmLF3NYz3uHPx1hLuhT2U2K
3543
```
3644

37-
Alternatively, you can use `pm2` to run the source code:
45+
### Using `pm2`
3846

39-
```
47+
You can also run the source code using `pm2`:
48+
49+
```sh
4050
npm install
4151
npm start
4252
```
4353

44-
You can run the Node using the following command:
54+
To start the NodeJS-FAAS using `pm2`:
4555

46-
```
56+
```sh
4757
pm2 start index.mjs --name NodeJS-FAAS
4858
```
4959

50-
# How to use?
51-
Currently, we provide an interface over [HTTP API](openapi.json). You can create a lambda function or upload code formatted in an `mjs` file to the instance, and you can execute the function using the API. Additionally, there are plans to add NATS.io or Pub/Sub to trigger a function.
60+
## Usage
61+
62+
Currently, NodeJS-FAAS provides an interface over an [HTTP API](openapi.json). You can create a lambda function or upload code in an `mjs` file to the instance and execute the function using the API. Future plans include adding NATS.io or Pub/Sub for function triggers.
5263

53-
# Example Code
64+
## Example Code
5465

55-
### Call Http API
66+
### Calling the HTTP API
5667

5768
```mjs
5869
const axios = require('axios');
5970

6071
function main(event, context, callback) {
61-
if(event=="get_nasa_image") {
72+
if (event === "get_nasa_image") {
6273
const { key } = context;
6374
axios.get(`https://api.nasa.gov/planetary/apod?api_key=${key}`)
64-
.then(response => {
65-
if(callback) callback({
66-
explanation: response.data.explanation
75+
.then(response => {
76+
if (callback) callback({
77+
explanation: response.data.explanation
78+
});
79+
})
80+
.catch(error => {
81+
if (callback) callback({
82+
error: error.message
83+
});
6784
});
68-
})
69-
.catch(error => {
70-
if(callback) callback({
71-
error: error.message
72-
});
73-
});
7485
}
7586
}
7687

77-
main(G_EVENT_NAME,G_CONTEXT,G_CALLBACK);
88+
main(G_EVENT_NAME, G_CONTEXT, G_CALLBACK);
7889
```
7990

80-
# Generate token
81-
Genarte the .env file
82-
`JWT_KEY=MY_SECRET_KEY`
91+
## Generating a Token
8392

84-
`apt-get update`
93+
To generate a token, visit the [JWT Generator Website](https://jwt.io/). Use the JWT_KEY you provided for the container and input the following content in the body, adjusting the parameters as needed:
8594

86-
`apt-get install jq jw`
95+
```json
96+
{
97+
"expire_at": "1735713720",
98+
"issued_at": "1721994397",
99+
"issuer": "shreyas",
100+
"namespace": "neo"
101+
}
102+
```

0 commit comments

Comments
 (0)