Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
Nodemon.io
Monitor for any changes in your node.js application and automatically restart the server - perfect for development
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
import { listenAndServe } from "https://deno.land/[email protected]/http/server.ts"; const addr = ":8080"; const handler = (request: Request): Response => { let body = "Your user-agent is:\n\n"; body += request.headers.get("user-agent") || "Unknown"; return new Response(body, { status: 200 }); }; console.log(`HTTP webserver running. Access it at: http://localhost:8080/`); await listenAndServe(addr, handler);
As you've already seen, you don't need to do anything besides install the Deno CLI for it to work. Like its predecessor, Deno uses the V8 runtime engine under the hood to parse and execute JavaScript code, but it also includes the TypeScript compiler in its executable to achieve TypeScript support.
Here's an example that uses Oak, a web application framework for Deno, to create a basic web server:
Here's an example that imports the dayjs NPM package from Skypack in a Deno script:
It also has a built-in file watcher that can be used with several of its subcommands. For example, you can configure deno run to automatically rebuild and restart a program once a file is changed by using the --watch flag. In Node.js, this functionality is generally achieved through some third-party package such as nodemon.
With Deno 1.6, you can compile scripts into self-contained executables that do not require Deno to be installed through the compile subcommand (you can use pkg to do the same in Node.js). You can also generate executables for other platforms (cross compilation) through the --target flag. When compiling a script, you must specify the permissions needed for it to run.
Two additional great tools that Deno ships with are the built-in linter (deno lint) and formatter (deno fmt). In the Node.js ecosystem, linting and formatting code are typically handled with ESLint and Prettier, respectively.
As well as other language smarts for any editor that supports the Language Server Protocol (LSP). You can learn more about setting up Deno support in your editor in Deno's online docs.
The short answer is: no. While you may not be able to utilize some NPM packages in Deno if they rely on Node.js APIs (especially if the specific APIs are not supported in Deno's Node.js compatibility layer), many NPM packages can be utilized in Deno through CDNs like esm.sh and skypack.dev. Both these CDNs provide NPM packages as ES Modules that can be subsequently consumed in a Deno script even if the author of the package did not design it to target Deno specifically.
Two additional great tools that Deno ships with are the built-in linter (deno lint) and formatter (deno fmt). In the Node.js ecosystem, linting and formatting code are typically handled with ESLint and Prettier, respectively.