Install Marko
Experiment with Marko directly in the browser using the Playground with no local setup.
Prerequisites
- Node.js
22.12or higher (see Supported Environments). - An editor: VS Code with the Official Marko extension, or any editor configured with the Marko Language Server.
- A terminal for running the CLI and development server.
Marko Run
Marko Run is the official application framework, powered by Vite. It is the recommended starting point for new projects.
npm init marko -- -t basic -n my-marko-app
cd my-marko-app
npm run devAvailable starter templates come from marko-js/examples:
| Template | Description |
|---|---|
basic | Marko Run starter with file-based routing |
app | Full Marko Run application with testing and styling setup |
library | Reusable component library with TypeScript and Storybook |
vite-express | Custom Express server integrated with @marko/vite |
Non-interactive environments (CI, piped stdin) accept defaults automatically. Pass flags to control scaffolding directly: -t for the template, -n / --name for the project directory, -y / --yes to accept defaults, --no-install to skip dependency installation, and --no-git to skip Git initialization.
Edit src/routes/+page.marko to modify the index page, and see File-based Routing to add routes.
Manual Setup
Projects with custom server or bundler architectures can configure Marko directly with @marko/vite or another supported bundler.
Vite with Express
Initialize an ESM project:
mkdir my-marko-app cd my-marko-app npm init -y npm pkg set type=moduleInstall Marko, Express, and Vite:
npm install marko express npm install -D vite @marko/viteRegister the Marko plugin in
vite.config.ts:import { defineConfig } from "vite"; import marko from "@marko/vite"; export default defineConfig({ plugins: [marko()], });Create a template at
src/routes/index.markoand a route module atsrc/routes/index.js:src/routes/index.marko<html lang="en"> <body> <h1>Hello Marko!</h1> </body> </html>html lang="en" body h1 -- Hello Marko!src/routes/index.jsimport template from "./index.marko"; export default function (_req, res) { res.header("Content-Type", "text/html"); template.render().pipe(res); }The page template rendered by a server route module is treated as a page entry by
@marko/vite, which automatically injects client assets when rendered.Create a development server in
index.js:import express from "express"; import { createServer } from "vite"; const app = express(); const vite = await createServer({ server: { middlewareMode: true }, appType: "custom", }); app.use(vite.middlewares); app.get("/", async (req, res, next) => { const handler = (await vite.ssrLoadModule("./src/routes/index.js")) .default; handler(req, res, next); }); app.listen(3000);For production builds and full server examples, see the
vite-expressexample.Start the development server and open http://localhost:3000:
node index.js
Browser-Only Setup
By default, @marko/vite links a server build with a browser build. For client-only applications without a server build, pass linked: false to marko() and mount the root template with Template.mount:
import { defineConfig } from "vite";
import marko from "@marko/vite";
export default defineConfig({
plugins: [marko({ linked: false })],
});<div id="app"></div>
<script type="module" src="/src/main.ts"></script>import App from "./app.marko";
App.mount({}, document.getElementById("app")!);With linked: false, @marko/vite cannot code-split lazy-loaded tags; with { load } imports compile as eager imports.
TypeScript Setup
Adding a tsconfig.json at the project root enables TypeScript inside .marko templates:
{
"include": ["src/**/*"],
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"lib": ["dom", "ESNext"],
"module": "ESNext",
"moduleResolution": "bundler",
"noEmit": true,
"noImplicitOverride": true,
"noUnusedLocals": true,
"outDir": "dist",
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ESNext",
"types": ["vite/client"],
"verbatimModuleSyntax": true
}
}For CLI and CI type checking, install @marko/type-check and run mtc instead of tsc:
npm install -D @marko/type-check
npx mtcSee the TypeScript reference for full type syntax and configuration details.
IDE Support
The Marko VS Code extension bundles syntax highlighting, formatting, TypeScript checking, and IntelliSense. Other editors can connect to the Marko Language Server.
Next Steps
Contributors
Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.