0
0
DenoHow-ToBeginner ยท 3 min read

How to Create a Fresh Project in Deno Quickly

To create a fresh project in deno, start by creating a new folder and adding a main script file like mod.ts. Then run your code with deno run and use deno task to manage scripts. Deno does not require a package manager or config file to start.
๐Ÿ“

Syntax

Creating a fresh Deno project mainly involves these steps:

  • Create a folder: This will hold your project files.
  • Add a main script file: Usually named mod.ts or main.ts.
  • Run your script: Use deno run [options] filename.ts to execute your code.
  • Optional tasks: Use deno task to define and run scripts from a deno.json config file.

Deno uses URL imports or local files directly, so no node_modules or package.json is needed.

bash
mkdir my-deno-project
cd my-deno-project
echo "console.log('Hello Deno!')" > mod.ts
deno run mod.ts
Output
Hello Deno!
๐Ÿ’ป

Example

This example shows how to create a simple Deno project that prints a greeting. It demonstrates creating a file, writing code, and running it.

typescript
console.log('Welcome to your fresh Deno project!');
Output
Welcome to your fresh Deno project!
โš ๏ธ

Common Pitfalls

Beginners often expect Deno to use package.json or node_modules like Node.js, but Deno does not. Also, forgetting to add --allow-net or other permissions when running scripts that access network or files causes errors.

Another common mistake is not using the .ts or .js extension in import statements, which Deno requires explicitly.

typescript
/* Wrong: Missing file extension in import */
import { serve } from "https://deno.land/std/http/server";

/* Right: Include file extension */
import { serve } from "https://deno.land/std/http/server.ts";
๐Ÿ“Š

Quick Reference

Summary tips for starting a Deno project:

  • Create a folder and add mod.ts as your entry file.
  • Run scripts with deno run mod.ts.
  • Use deno task with deno.json for script automation.
  • Always specify file extensions in imports.
  • Grant permissions explicitly when needed (e.g., --allow-net).
โœ…

Key Takeaways

Start a Deno project by creating a folder and a main script file like mod.ts.
Run your code with deno run and specify needed permissions explicitly.
Deno does not use package.json or node_modules; imports need full file extensions.
Use deno task and deno.json to manage scripts and tasks easily.
Always check permissions and import paths to avoid common errors.