On this page
Deploy an app with the deno deploy command
Thedeno deploy command provides a powerful CLI for deploying and managingapplications onDeno Deploy.
If you already have an app to deploy you can skip toDeploying your application, or read on to make andthen deploy a simple app.
PrerequisitesJump to heading
Before using the deploy command, you will need a Deno Deploy account, and a DenoDeploy organization set up on that account.
To create an account visitthe Deno Deploy dashboard. To create anorganization, follow the steps in the
Create a simple web applicationJump 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-appcd my-deploy-appInitialize a new Deno project:
deno initReplace the contents ofmain.ts with a simple HTTP server:
Deno.serve({ port:8000},(req)=>{const url=newURL(req.url);const userAgent= req.headers.get("user-agent")||"unknown";const timestamp=newDate().toISOString();// Log every requestconsole.log(`[${timestamp}]${req.method}${url.pathname} - User-Agent:${userAgent}`,);// Simple routingif(url.pathname==="/"){console.log("Serving home page");returnnewResponse(` <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");returnnewResponse(` <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:newDate().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 loggingconsole.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:newDate().toISOString(), tip:"Check the logs with: deno deploy logs",},{ status:500});}// 404 for all other routesconsole.warn(`404 - Route not found:${url.pathname}`);returnnewResponse("Not Found",{ status:404});});Test your application locallyJump to heading
Update thedev task in thedeno.json file in the root, to allow networkaccess:
"dev":"deno run -N --watch main.ts"Then run the dev command:
deno run devVisithttp://localhost:8000 to see your application running. Try navigating tothe different routes (/about,/api/status, and/api/error) to verifyeverything works. You'll notice that each request is logged to the console -these are the same logs you'll be able to see when the app is deployed!
AuthenticationJump to heading
Thedeno deploy command handles authentication automatically. When you firstrun a deploy command, it will prompt you to authenticate. Run the deploy commandwith the--help flag to see all available options:
deno deploy--helpThedeno deploy command requires a Deno Deploy organization. If you don'talready have an organization set up in your account, you can create one throughtheDeno Deploy web app.
Deploy your applicationJump to heading
Now let's use thedeno deploy command to deploy your application! Ensure thatyou are in the root directory of your project and run:
deno deploySelect the appropriate options in the terminal when prompted.
The deployment process will:
- Make a tarball of your application code
- Upload the tarball to Deno Deploy
- Unpack the tarball
- Build and deploy to the edge network
- Provide you with a live URL
You have now successfully deployed your application! You can visit the returnedURL to see your app in action.
If you need to make changes to your application, simply update your code and runthedeno deploy command again.
Our demo application had some logging built in, we can use the built in loggingfeatures of Deno Deploy to monitor the application.
Monitoring your applicationJump to heading
View application logsJump to heading
After deploying your application, you can stream live logs to see exactly what'shappening on the app:
deno deploy logsVisit your application URL and navigate to different pages. You'll see logslike:
- Request logs showing HTTP method, path, and user agent
- Info logs from
console.log()calls - Warning logs from
console.warn()calls - Error logs from
console.error()calls
Open your app url in the browser and try visiting the/api/error endpoint tosee the error logs in action.
View logs for a specific time rangeJump to heading
To view logs for a specific time range, you can use the--start and--endflags:
deno deploy logs\--start"2024-01-01T00:00:00Z"\--end"2024-01-01T23:59:59Z"Managing environment variablesJump to heading
Your application might need environment variables for configuration. Thedeno deploy command provides comprehensive environment variable management.
List environment variablesJump to heading
You can view all environment variables for your application:
deno deployenv listAdd and update environment variablesJump to heading
To add individual environment variables, use thedeno deploy env add command,for example:
deno deployenvadd API_KEY"your-secret-key"deno deployenvadd DATABASE_URL"postgresql://..."Then to update them, use thedeno deploy env update-value command, forexample:
deno deployenv update-value API_KEY"new-secret-key"deno deployenv update-value DATABASE_URL"postgresql://new-user:new-pass@localhost/new-db"Delete environment variablesJump to heading
To delete an environment variable, use thedeno deploy env delete command, forexample:
deno deployenv delete API_KEYdeno deployenv delete DATABASE_URLLoad environment variables from a .env fileJump to heading
You can also use an.env file to load your environment variables to yourdeployed app:
deno deployenv load .env🦕 You've successfully deployed your first application with thedeno deploycommand! Check out thedeno deploy docs formore commands and options.
For more information on Deno Deploy, check theDeno Deploy documentation.