Installation
System requirements:
- Nodejs 20.X (opens in a new tab) or later
- MacOS, Windows and Linux are all supported.
10 seconds setup
To get started, type the following command:
npm create sensai
# or
npx create-sensaiOn installation, you'll see the following prompts:
? What is your project named? › hello-worldThe CLI create-sensai automatically install/setup your project dependencies,
allowing you to start coding immediately!
Manual Installation
To manually install Sensai in your project, please:
Install dependencies
npm install sensai@latestAdd scripts
Open your project package.json and add the following scripts:
{
"scripts": {
"dev": "sensai dev",
"build": "sensai build",
"start": "sensai start"
}
}Those scripts accompany you at each step of the development process:
devrun development server (with live reload, automatic documentation and more)buildbuild and optimize production artifacts and documentationstartrun the fastest production server in the west
Sensai provides an integrated TypeScript experience, including on the fly transpilation, zero-configuration set up and dependencies.
Create api folder
Create an api folder at the root of your project and add a basic route.ts file.
export default ({ name = "world" }) => {
return "hello " + name;
};Congratulation, you created your first API. This will be served everytime a user send a request to the path /.
Please note that routes can also be written in Javascript by using the .js,
.mjs or .cjs extension. Your project can contain both JavaScript and/or
TypeScript routes.
Run development server
After the set up is complete:
- Run
npm run dev(oryarn devorpnpm dev) to start the development server on http://localhost:3030 (opens in a new tab) - Visit http://localhost:3030/api (opens in a new tab) to view your first API
- Change the URL to be http://localhost:3030/api?name=Bob (opens in a new tab)
- Edit
api/route.tsand visit the link above again (no need to restart the server)
With Sensai, creating an API is as easy as writing a function with data as input and data as output. Everything is taken care of and developers don't need to get bogged down anymore in the details of request handling and response generation.