Node.js เริ่มต้น Hello World

บทความนี้จะเป็นการสอนสร้างไฟล์ไว้สำหรับรัน Node.js อย่างที่รู้กัน Node.js เป็น Javascript ดังนั้นสิ่งที่เราจะสร้างในบทความนี้คือไฟล์ Javascript

Javascript เริ่มต้น

สำหรับผู้ที่เขียน Javascript มาก่อนก็จะรู้ว่าการที่เราจะแสดงข้อความออกมาจะใช้คำสั่งที่อยู่ว่า

console.log("ข้อความ");

ให้เราสร้างไฟล์ .js ไว้ที่ไหนก็ได้ Folder หนึ่ง โดยไฟล์ .js นี้ ให้ตั้งชื่อว่า

app.js

โดยไฟล์ app.js ให้เขียนโค้ด

console.log("hello world");

พอสร้างเสร็จให้รันคำสั่งใน cmd โดยเราต้องอยู่ใน Folder ที่เราเก็บไฟล์ app.js ด้วย

node app.js

จะได้หน้าต่างดังรูป

cmd หลังจากรันคำสั่ง node

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade