Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

start with npm init

app.get/post(route,middleware,function)

ตัวอย่าง

app.get("/", function (req, res) {
  res.send("hello world");
});

app.post("/", function (req, res) {
  // res.send("hello world");
  res.status(200).send({ massage: "you get 200" });

});
  • send อันเดียวจะจบเลยเหมือน return
  • การใช้ get จะไม่ encode ข้อมูลให้สามารถอ่านได้เราจึงไม่นิยมส่ง body ไปด้วย
  • ถ้าจะส่ง body จะใช้ push ถึงจะมีการ encode

middleware

  • ใช้ตรวจสอบ auth
  • แก้ไข req ก่อนเข้าไปทำอื่นๆต่อ
  • ทำอะไรบางอย่างก่อนที่จะไปทำอื่นๆต่อ

เรื่องที่ต้องไปดูเพิ่มเติม

About

nodeJS -> express เบื้องต้นแบบมากๆไม่มี basic กว่านี้แล้ว

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages