A secure runtime for JavaScript and TypeScript
Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.
-
Node.js is written in C++; Deno is written in Rust
-
Event-Loop: Node.js use libuv; Deno use Tokio library
-
The dependency manager: Node.js use package.json and NPM
-
Dependency folder: Deno use global cache folder(It defaults to the system's cache directory, also can be specified by DENO_DIR); Node.js use node_modules in every project
-
import module: Deno support ES Moudule syntax, Node.js use requre() which is CommonJS syntax; Deno need to specify ext
-
specific permissions, security
-
GYP
-
One delivrable, one executable: deno bundle, deno compile
-
ecosystem
-
Deno is compatible with Browser
-
Deno provides built-in tooling like unit testing, code formatting, and linting to improve developer experience.
10 Things I Regret About Node.js
- 100 concurrent connections
|Name|version|AVG req/sec| |---|---|---|---| |node.http|12.16.3|47969.2| |deno.http|1.0.0|47376| |deno.http|1.1.0|46953.7| |node.http|14.2.0|44409|
- 10 concurrent connections
|Name|version|AVG req/sec| |---|---|---|--- |node.http|12.16.3|49926.69| |node.http|14.2.0|45345.33| |deno.http|1.1.0|34806.79| |deno.http|1.0.0|34742.37|
# install
curl -fsSL https://deno.land/x/install/install.sh | sh
## or
brew install deno
# update
deno upgrade
Deno uses command-line options to explicitly allow access to different parts of the system
- environment access
- network access
- file system read/write access
- running a subprocess
deno run {local filepath}
# or
deno run {remote url}
like nodemon, will auto restart server if file changes in watching dirs
First, need to install denon
, if occur error, try to update your deno and then try install again
deno install --unstable --allow-read --allow-run -f https://deno.land/x/denon/denon.ts
Then, touch a local configuration files for denon
{
"files": [
"./example/server.ts",
"./example/static_server.ts"
],
"quiet": false,
"debug": true,
"fullscreen": true,
"extensions": [
".js",
".ts",
".py",
".json"
],
"interval": 500,
"watch": [
"./"
],
"deno_args": [
"--allow-net",
"--allow-read",
"--import-map=import-map.json"
],
"scripts": {
"start_static": {
"cmd": "./example/static_server.ts",
"desc": "run static server"
},
"start": {
"cmd": "./example/server.ts",
"desc": "run server"
},
"test": {
"cmd": "deno test",
"desc": "exec test"
}
},
"execute": {
".js": [
"deno",
"run"
],
".ts": [
"deno",
"run"
],
".py": [
"python"
]
},
"allow": [
"net",
"read"
],
"fmt": false,
"unstable": true,
"test": true
}
Finally, run in watching mode
denon -c {configuration file path}
-
Standard Library A standard set of high quality code, which are reviewed by the Deno core team
-
Custom Local library
-
Import statements can make use of URLs
# standard library https://deno.land/std/<PATH_TO_MODULE>.ts https://deno.land/std@{VERSION}/<PATH_TO_MODULE>.ts
-
Import statements must have a file ending
This will run all files in the working directory that end in _test
or .test
with the extension .js
, .ts
, .jsx
, or .tsx
deno test
Deno successfully removes many of the drawbacks from Node.js development
Hope it's a better Node.js
It may not com replace Node.js
Deno 1.0: What you need to know