티스토리 뷰

Dev./Deno

[Deno] hello world 해보기

인쥭 2022. 5. 31. 14:05
반응형
 

Deno - A modern runtime for JavaScript and TypeScript

Deno is a simple, modern runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

deno.land

로고가 너무 귀여워 안해볼 수가 없었다.

  • MDN web docs를 보다가 못보던 아이콘이 보여서 찾아보게 되었고, macOS에서 간단하게 설치해 볼 수 있었다.

-> 독보적인 존재감

Deno란?

  • Deno는 JS / TS 런타임이며, Node.js의 Ryan Dahl이 주도하는 프로젝트이다.
  • 아무래도 라이언 형이 Node.js에서 있었던 아쉬운 점, 또는 미련을 Deno를 통해 상당 부분 해소(?)하려는 것 같다.

설치하기(macOS)

  • brew를 통해 간단하게 설치할 수 있다.
  • macOS가 아닌 다른 OS의 경우 링크를 확인하자!
[~] brew install deno
// 설치 과정 생략
[~] deno --version
deno 1.22.0 (release, x86_64-apple-darwin)
v8 10.0.139.17
typescript 4.6.2
[~]

Hello World

  • 적당한 디렉토리에 간단한 ts 파일을 작성한 후, deno run 명령어로 실행할 수 있다.
// my-first-deno.ts
type Person = {
    name: string;
    age: number;
    alias: string;
}

function sayHello(who: Person): void {
    const { name, age, alias } = who;
    console.log(`Hello, ${name}(or ${alias})! [${age} years old]`);
}

sayHello({
   name: 'ingnoh',
   age: 3,
   alias: 'injuk',
});
  • 해당 코드는 컴파일 과정이나 ts-node 없이 Node.js로 실행할 수는 없다.
[~] node my-first-deno.ts
/Your/Folders/deno/my-first-deno.ts:1
type Person = {
     ^^^^^^

SyntaxError: Unexpected identifier
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47
[~]
  • 그러나 Deno는 TS 런타임이기도 하므로, 바로 실행해볼 수 있다.
[~] deno run my-first-deno.ts
Check file:///Your/Folders/deno/my-first-deno.ts
Hello, ingnoh(or injuk)! [3 years old]
[~]
  • 이 밖에도 Deno 만의 여러 특징이 있는 것 같은데, 이 부분은 차차 공부해나가며 문서를 추가하기로 했다.
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함