On this page
Deploy an app with the deno deploy command
The deno deploy command provides a powerful CLI for deploying and managing
applications on Deno Deploy.
If you already have an app to deploy you can skip to Deploying your application, or read on to make and then deploy a simple app.
Prerequisites Jump to heading
Before using the deploy command, you will need a Deno Deploy account, and a Deno Deploy organization set up on that account.
To create an account visit the Deno Deploy dashboard. To create an organization, follow the steps in the
Create a simple web application Jump to heading
First, let's create a basic HTTP server that will serve as our application.
Create a new directory for your project and navigate into it:
›_
mkdir my-deploy-app
cd my-deploy-app
Initialize a new Deno project:
›_
deno init
Replace the contents of main.ts with a simple HTTP server:
main.ts
Deno.serve({ port: 8000 }, (req) => {
const url = new URL(req.url);
const userAgent = req.headers.get("user-agent") || "unknown";
const timestamp = new Date().toISOString();
// Log every request
console.log(
`[${timestamp}] ${req.method} ${url.pathname} - User-Agent: ${userAgent}`,
);
// Simple routing
if (url.pathname === "/") {
console.log("Serving home page");
return new Response(
`
<html>
<head><title>My Deploy App</title></head>
<body>
<h1>Welcome to My Deploy App!</h1>
<p>This app was deployed using the deno deploy command.</p>
<nav>
<a href="/about">About</a> |
<a href="/api/status">API Status</a> |
<a href="/api/error">Test Error</a>
</nav>
</body>
</html>
`,
{
headers: { "content-type": "text/html" },
},
);
}
if (url.pathname === "/about") {
console.log("Serving about page");
return new Response(
`
<html>
<head><title>About - My Deploy App</title></head>
<body>
<h1>About This App</h1>
<p>This is a simple demonstration of deploying with the deno deploy CLI.</p>
<p>Check the logs to see request information!</p>
<a href="/">← Back to Home</a>
</body>
</html>
`,
{
headers: { "content-type": "text/html" },
},
);
}
if (url.pathname === "/api/status") {
const responseData = {
status: "ok",
timestamp: new Date().toISOString(),
message: "API is running successfully",
requestCount: Math.floor(Math.random() * 1000) + 1, // Simulate request counter
};
console.log("API status check - all systems operational");
console.log(`Response data:`, responseData);
return Response.json(responseData);
}
if (url.pathname === "/api/error") {
// This endpoint demonstrates error logging
console.error("Error endpoint accessed - demonstrating error logging");
console.warn("This is a warning message that will appear in logs");
return Response.json({
error: "This is a test error for demonstration",
timestamp: new Date().toISOString(),
tip: "Check the logs with: deno deploy logs",
}, { status: 500 });
}
// 404 for all other routes
console.warn(`404 - Route not found: ${url.pathname}`);
return new Response("Not Found", { status: 404 });
});