- Published on
Running Node.js Projects Using Deno 2: A Step-by-Step Guide
- Authors

- Name
- Mehdi Akiki
With the release of Deno 2, one of the most exciting features it introduces is native Node.js and npm compatibility. This update allows developers to run Node.js projects with Deno without relying on the traditional node_modules directory. In this article, we’ll explore how to run an actual Node.js project using Deno, leveraging npm packages natively.
Why Deno 2’s npm Compatibility Matters
Traditionally, Deno operates differently from Node.js, requiring its own module system. However, with Deno 2, the gap between the two ecosystems is bridged, allowing developers to run Node.js projects and npm packages in Deno's secure environment. You can now run a Node.js project directly in Deno without needing pre-installed node_modules.
How to Run a Node.js Project in Deno 2
Follow these steps to run a Node.js project in Deno:
1. Install Deno 2.0
Make sure you have Deno 2 installed. You can check the installation guide in the official Deno documentation.
2. Navigate to Your Node.js Project
In your terminal, navigate to the root directory of your Node.js project.
cd /path/to/your/node/project
3. Initialize npm Compatibility
Deno 2 can now read package.json files and manage npm dependencies. To install the necessary dependencies for the Node.js project, use:
deno task npm install
This will fetch the required npm packages, and Deno will handle them natively without creating a node_modules directory.
4. Run the Node.js Project
Once the dependencies are installed, you can run the project using the deno run command.
deno run --allow-net app.js
Here, --allow-net is a permission flag to allow network access if your app needs it. Deno enforces strict security, so you’ll need to explicitly allow permissions such as file system access (--allow-read, --allow-write) or environment variables (--allow-env).
Example Project: Running an Express App with Deno
Let’s say you have a simple Express app as your Node.js project. Here’s how you’d run it with Deno:
Install Express with Deno's npm support:
deno npm install express
Run the Project:
deno run --allow-net app.js
Deno will manage Express and its dependencies, ensuring it runs seamlessly without needing a node_modules directory.
Key Differences Between Deno and Node.js in This Context
- No node_modules Directory: Deno doesn't create a local
node_modulesdirectory. Instead, it fetches and caches dependencies globally in a central location. - Permission Flags: Deno requires explicit permission flags for network access, file system access, and other potentially risky operations. This ensures security by default.
- Unified Ecosystem: Deno natively supports both Deno modules and Node.js npm modules, simplifying cross-environment development.
Conclusion
Deno 2’s npm and Node.js compatibility is a game-changer for developers looking to use Deno's security features while maintaining access to npm's extensive package ecosystem. Running a Node.js project in Deno has never been easier, with no need for a local node_modules directory and minimal changes to your project setup. If you're interested in exploring more, check out the official Deno documentation.
By integrating Deno’s modern, secure design with Node.js's expansive package system, Deno 2 opens up new possibilities for JavaScript development.
I build and scale reliable production systems. Open to full-time and freelance work with U.S.-based teams that value ownership and execution.
Got something in mind?
Book a Discovery Call