DEV Community

Cover image for Deno v1.0 ออกแล้ว! ตัวเลือกใหม่สำหรับ JavaScript Runtime แทน Node.js
Ta for tamemo

Posted on • Edited on • Originally published at centrilliontech.co.th

2

Deno v1.0 ออกแล้ว! ตัวเลือกใหม่สำหรับ JavaScript Runtime แทน Node.js

Deno เป็นเอ็นจิน runtime ที่เอาไว้รันภาษา JavaScript (และ TypeScript) คล้ายๆ กับ V8-Engine ที่ใช้ใน Node.js

สร้างโดย Ryan Dahl ที่เป็นผู้เริ่มโครงการ Node.js ตั้งแต่ปี 2009
ตอนแรกพัฒนาด้วยภาษา Go แต่เปลี่ยนไปเขียนด้วยภาษา Rust แทนในภายหลัง (V8 ใช้ C++)

ฟีเจอร์เด่นๆ ของ Deno

  • Support TypeScript: นี่น่าจะเป็นข้อดีอันดับต้นๆ เลยล่ะ เพราะตามกฎการเขียน JavaScript ที่กล่าวไว้ว่า "คุณไม่ควรเขียน JavaScript!...ให้เขียน TypeScript แทน" (ฮา)
  • Security by default: แอพพลิเคชันที่รัน จะไม่สามารถเข้าถึงระบบ File System, Network, หรือพวก Environment ได้เลยถ้ายังไม่มีการกำหนดสิทธิตอนรันให้ เช่นต้องใส่ flag --allow-net เพิ่ม
  • มี build-in utilities ให้ใช้ เช่น dependency inspector, code formatter
  • สำหรับ standard modules นั้นมีกลุ่ม reviewer คอยเช็กความถูกต้องและเทสเพื่อการันตีว่ามันทำงานได้เวิร์คจริงๆ นะ

มี Node.js อยู่แล้ว จะสร้าง Deno มาทำไม?

Ryan Dahl ผู้สร้าง Deno บอกเอาไว้ว่า
JavaScript นั้นเปลี่ยนไปมากหลังจาก Node.js ถูกสร้างขึ้นตั้งแต่ปี 2009
อารมณ์ก็คล้ายๆ กับภาษา PHP ที่ไม่ได้ออกแบบโครงสร้างที่ดีมาตั้งแต่ต้น พอจะต่อเติมอะไรเข้าไปเพิ่มก็ทำได้ยาก

เช่น Module System นั้นออกแบบมาไม่ดีตั้งแต่แรก, มี API เก่าที่ควรเลิกใช้ได้แล้วแต่ก็ยังต้องทำงานอยู่, ความปลอดภัย

Ryan Dahl บอกว่าถึงแม้ Deno มันจะหน้าตาดูคล้ายๆ Node.js แต่มันถือว่าเป็นคนละตัวกันเลยนะ ตอนนี้ Deno ยังใหม่มาก อาจจะยังไม่เหมาะกับการใช้งานในบางโปรเจค โดยเฉพาะโปรเจคที่ยังต้องพึ่ง library จาก npm อยู่

installation

เข้าไปดูจาก https://deno.land/ ได้เลย

Hello World

ตัวอย่างการสร้าง server แบบง่ายๆ จะเห็นว่ามันเป็น JavaScript นั่นแหละ แต่มันไม่ใช่ Node.js

import { serve } from "https://deno.land/std@0.50.0/http/server.ts";

const s = serve({ port: 8000 });
console.log("http://localhost:8000/");

for await (const req of s) {
  req.respond({ 
    body: "Hello World\n" 
  });
}
Enter fullscreen mode Exit fullscreen mode

Deno เพิ่งออกเวอร์ชัน 1.0 ตอนนี้ก็ต้องรอดูกันต่อไป ว่าไดโนเสาร์ตัวนี้จะมาแทน Node.js ได้ในอนาคตหรือไม่?

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Image of Stellar post

🚀 Stellar Dev Diaries Series: Episode 1 is LIVE!

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay