The serverless framework creates web servers that can run anywhere.
- π 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.
- Create an aircode app
npx create-aircode-app@latest my-aircode-app && cd my-aircode-app
- Install dependencies and run
npm i && npm start
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
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>
.
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;