@aircodelabs/hydrogen
v0.7.0
Published
<img width="168" alt="未标题-3" src="https://github.com/AirCodeLabs/Hydrogen/assets/316498/013996f1-69b9-4208-887f-2dab00b45cab">
Downloads
22
Keywords
Readme
Hydrogen
The serverless framework creates web servers that can run anywhere.
Features
- 🐇 Rapid development with Hot Module Replacement (HMR) 🔥
- 📦 Supports CommonJS (.js .cjs), ES modules (.mjs), and TypeScript (.ts) functions out of the box.
- 🧸 Requires almost zero configurations.
- 🗄️ Comes with a built-in, ready-to-use text database and file API.
- 📁 Follows intuitive directory structure conventions.
- 🤏 Written in Pure JavaScript with a sleek and minimalist design.
- ⚡️ Optimized for runtime performance, regardless of development or production environments.
- 🧊 Compatible and capable of running your app seamlessly on the AirCode platform.
Getting Started
- Create an aircode app
npx create-aircode-app@latest my-aircode-app && cd my-aircode-app
- Install dependencies and run
npm i && npm start
Directory Structure
The default project directory structure is very simple.
├──functions # put your function api here.
│ └── hello.js # http://localhost:3000/hello
├──public # put your static resources here.
│ └── favicon.ico # http://localhost:3000/public/favicon.ico
└── package.json
Build Cloud Functions
You can easily build your function api in ./functions
directory.
- With
*.js
or*.cjs
// myfun.js
const aircode = require('aircode');
module.exports = async function(params, context) {
console.log('Received params:', params);
return {
message: 'Hi, AirCode.'
};
}
- Or with
*.mjs
import aircode from 'aircode';
export default async function (params, context) {
console.log('Received params:', params);
return {
message: 'Hi, AirCode.',
};
};
- Or with
*.ts
import aircode from 'aircode';
export default async function (params: any, context: any) {
console.log('Received params:', params);
return {
message: 'Hi, AirCode.',
};
};
Simply visit your built functions with http://localhost:3000/<your_func_name>
.
And visit your static resources with http://localhost:3000/public/<your_static_file>
.
Documentation
Configurations
There are a few options that you can pass through process.env.
process.env.AC_FAAS_ROOT = process.env.AC_FAAS_ROOT || 'functions';
process.env.AC_PUBLIC_DIR = process.env.AC_PUBLIC_DIR || 'public';
process.env.AC_PORT = process.env.AC_PORT || 3000;