Dear friends, hello everyone. We recently got a new stable version of the wheel. Did you study?
I’m going to take you through 100 seconds of deno.
The installation
-
Using Shell:
curl -fsSL https://deno.land/x/install/install.sh | sh
-
Using PowerShell:
iwr https://deno.land/x/install/install.ps1 -useb | iex
-
Using Homebrew (macOS or Linux):
brew install deno
-
Using Chocolatey (Windows):
choco install deno
To view
Run deno –help on the command line
We should see the following information.
In the image above we can see the deno version and some other information.
We also found an existing example above. So let’s just run through this example.
deno run https://deno.land/std/examples/welcome.ts
See Welcome to Deno 🦕, right
Let’s take a look at what’s inside the execution file.
Yes, you read that right. It’s a console.log
A new demo
Let’s create a file and try it out locally.
Create the file hello-mien.ts
console.log('hello mien, this is my first deno demo ~ 🦕')
Copy the code
Let’s run this file.
deno run ./hello-mien.ts
At this point we have completed a simple Hello World example.
Watch something interesting.
As a front-end programmer, tell me, which method do you use the most?
Say it silently.
3
2
1
Console. log is correct?
Now that we’ve run a command with deno, we need to look at the deno global variable
Let’s add a line of logs to see what’s in the global Deno.
console.log(Deno);
Run the script deno run./hello-mien.ts
We can see Deno’s content
{
Buffer: [Function: Buffer],
readAll: [AsyncFunction: readAll],
readAllSync: [Function: readAllSync],
writeAll: [AsyncFunction: writeAll],
writeAllSync: [Function: writeAllSync],
build: {
target: "x86_64-pc-windows-msvc",
arch: "x86_64",
os: "windows",
vendor: "pc",
env: "msvc"
},
chmodSync: [Function: chmodSync],
chmod: [AsyncFunction: chmod],
chownSync: [Function: chownSync],
chown: [AsyncFunction: chown],
customInspect: Symbol(Deno.symbols.customInspect),
inspect: [Function: inspect],
copyFileSync: [Function: copyFileSync],
copyFile: [AsyncFunction: copyFile],
DiagnosticCategory: {
0: "Log",
1: "Debug",
2: "Info",
3: "Error",
4: "Warning",
5: "Suggestion",
Log: 0,
Debug: 1,
Info: 2,
Error: 3,
Warning: 4,
Suggestion: 5
},
chdir: [Function: chdir],
cwd: [Function: cwd],
errors: {
NotFound: [Function: NotFound],
PermissionDenied: [Function: PermissionDenied],
ConnectionRefused: [Function: ConnectionRefused],
ConnectionReset: [Function: ConnectionReset],
ConnectionAborted: [Function: ConnectionAborted],
NotConnected: [Function: NotConnected],
AddrInUse: [Function: AddrInUse],
AddrNotAvailable: [Function: AddrNotAvailable],
BrokenPipe: [Function: BrokenPipe],
AlreadyExists: [Function: AlreadyExists],
InvalidData: [Function: InvalidData],
TimedOut: [Function: TimedOut],
Interrupted: [Function: Interrupted],
WriteZero: [Function: WriteZero],
UnexpectedEof: [Function: UnexpectedEof],
BadResource: [Function: BadResource],
Http: [Function: Http],
Busy: [Function: Busy]
},
File: [Function: File],
open: [AsyncFunction: open],
openSync: [Function: openSync],
create: [Function: create],
createSync: [Function: createSync],
stdin: Stdin { rid: 0 },
stdout: Stdout { rid: 1 },
stderr: Stderr { rid: 2 },
seek: [Function: seek],
seekSync: [Function: seekSync],
read: [AsyncFunction: read].readSync: [Function: readSync],
write: [AsyncFunction: write],
writeSync: [Function: writeSync],
watchFs: [Function: watchFs],
internal: Symbol(Deno.internal),
copy: [AsyncFunction: copy],
iter: [AsyncGeneratorFunction: iter],
iterSync: [GeneratorFunction: iterSync],
SeekMode: { 0: "Start", 1: "Current", 2: "End", Start: 0, Current: 1, End: 2 },
makeTempDirSync: [Function: makeTempDirSync],
makeTempDir: [Function: makeTempDir],
makeTempFileSync: [Function: makeTempFileSync],
makeTempFile: [Function: makeTempFile],
metrics: [Function: metrics],
mkdirSync: [Function: mkdirSync],
mkdir: [AsyncFunction: mkdir],
connect: [AsyncFunction: connect],
listen: [Function: listen],
dir: [Function: dir],
env: { get: [Function: getEnv], toObject: [Function: toObject], set: [Function: setEnv] },
exit: [Function: exit].execPath: [Function: execPath],
run: [Function: run],
Process: [Function: Process],
readDirSync: [Function: readDirSync],
readDir: [Function: readDir],
readFileSync: [Function: readFileSync],
readFile: [AsyncFunction: readFile],
readTextFileSync: [Function: readTextFileSync],
readTextFile: [AsyncFunction: readTextFile],
readLinkSync: [Function: readLinkSync],
readLink: [Function: readLink],
realPathSync: [Function: realPathSync],
realPath: [Function: realPath],
removeSync: [Function: removeSync],
remove: [AsyncFunction: remove],
renameSync: [Function: renameSync],
rename: [AsyncFunction: rename],
resources: [Function: resources],
close: [Function: close],
statSync: [Function: statSync],
lstatSync: [Function: lstatSync],
stat: [AsyncFunction: stat],
lstat: [AsyncFunction: lstat],
connectTls: [AsyncFunction: connectTls],
listenTls: [Function: listenTls],
truncateSync: [Function: truncateSync],
truncate: [AsyncFunction: truncate],
isatty: [Function: isatty],
version: { deno: "1.0.0 - rc2", v8: "8.4.300", typescript: "3.8.3" },
writeFileSync: [Function: writeFileSync],
writeFile: [AsyncFunction: writeFile],
writeTextFileSync: [Function: writeTextFileSync],
writeTextFile: [AsyncFunction: writeTextFile],
test: [Function: test],
core: {
print: [Function],
recv: [Function],
send: [Function],
setMacrotaskCallback: [Function],
evalContext: [Function],
formatError: [Function],
encode: [Function],
decode: [Function],
getPromiseDetails: [Function],
shared: SharedArrayBuffer {},
setAsyncHandler: [Function: setAsyncHandler],
dispatch: [Function: dispatch],
sharedQueue: {
MAX_RECORDS: 100,
head: [Function: head],
numRecords: [Function: numRecords],
size: [Function: size],
push: [Function: push],
reset: [Function: reset],
shift: [Function: shift]
},
ops: [Function: ops]
},
args: [],
pid: 18188,
noColor: false,
Symbol(Deno.internal): {}
}
Copy the code
So, we are familiar with those methods and they are still the same
Take a look at the path.
Deno.cwd()
Run the script and we get an error!
Uncaught PermissionDenied: read access to “***” run again with the --allow-read
flag
This is deno’s security policy, and by default you don’t have access.
If you add –allow-read, you get the desired result.
import
First let’s go to the official tagging library and find something interesting.
Modify the code
import { red, blue, white } from 'https://deno.land/std/fmt/colors.ts';
console.log(red('i\'m red text'));
console.log(blue('i\'m blue text'));
console.log(white('i\'m white text'));
Copy the code
Execute the script
PS: Libraries or files imported through external addresses are cached locally after the first import.
OK, that’s all for this time. There’s a lot we need to rethink about deno. This is just a very simple demo, so if you are interested, try it out for yourself.
Mien has 5 years of front-end development experience and is currently with Schlumberger.
Scope: Angular, Vue, React, applet, electron, nodeJS, and a bunch of other messy technologies
Welcome to leave your questions and corrections.
See you next time