Skip to content
create kosmo

A KosmoJS project starts with the create kosmo command:

sh
npm create kosmo

Use . to bootstrap in the current directory:

sh
npm create kosmo .

You'll be asked for:

  • Name - the project name (unless . used to bootstrap in current directory)
  • Frontend - React, Vue, Solid, Svelte, MDX, or None (API-only folder)
  • Backend - Hono, H3, Koa, or None (client-only folder)

The first source folder is always app, with its pages at / and its API at /api. Add differently-shaped folders at any time with kosmo folder.

If the target directory has anything in it other than .git*, README* or LICENSE*, you are asked first what to do with it:

  • Remove the existing files
  • Keep them and overwrite as needed
  • Cancel

CLI mode ​

Provide up front the --name and --frontend/--backend (or --no-frontend/--no-backend counterparts) and no prompts appear:

sh
# npm needs an extra -- to pass flags through
npm create kosmo -- --name demo --frontend solid --backend hono
FlagMeaning
--name <name>Project name. Ignored when using . to bootstrap in current directory
--frontend <stack>react, solid, vue, svelte, mdx.
--no-frontendAPI-only folder - no pages/, no client entries.
--backend <stack>hono, h3, koa.
--no-backendClient-only folder - no api/ directory.
--overwriteProceed even though the target directory is not empty.
-h, --helpPrint usage and exit.

The frontend and backend choices are never implied

Either --frontend <stack> or --no-frontend is required - omitting both is an error, and passing them both is an error too (same for backend).

What you get ​

txt
demo/
├── .gitignore
├── package.json
├── tsconfig.json
├── lib/                       # generated support code, reached through `_/`
└── src/app/
    ├── kosmo.config.ts        # the frontend / backend blocks your answers imply
    ├── tsconfig.json
    ├── index.html
    ├── app.tsx                # root component, extension per framework
    ├── router.ts
    ├── components/Link.tsx    # the typed Link
    ├── pages/404.tsx          # the 404 page
    ├── entry/client.ts        # the client entry
    ├── entry/server.ts        # the server entry, used by SSR builds
    ├── public/favicon.svg
    └── api/                   # if a backend was chosen
        ├── app.ts             # app middleware, the native instance
        ├── use.ts             # global middleware
        ├── errors.ts          # the default error handler
        ├── dev.ts             # dev-only hooks
        ├── server.ts
        └── env.d.ts           # global context types

Every one of those files comes filled in. What the scaffold does not write is routes - api/ has no endpoints and pages/ no index page yet.


After bootstrap ​

cd into freshly created project (unless the project was bootstrapped in the current folder):

sh
cd ./demo

Install Dependencies ​

sh
npm install

Start the dev server ​

The dev server watches your routes and recomputes as you work - and seeds starter code into any route or page file you create empty:

sh
npm run dev

Your app is now running at http://localhost:4556.

Released under the MIT License.