2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js Express4.Xで middlewareとしてasync function

Posted at

# なんか出来るっぽい

async functionはawaitしない場合Promiseオブジェクトが返却されます。
普通のfunctionとは違うので、どうなるか気になったので調べてみた

express-generatorで生成されるapp.jsに対して
以下の様にasync function を使ったミドルウェアを追加しても
next()が生きていてその後の処理に進んでいた。

app.js

app.use(async function(req ,res ,next){
  console.log("async func")
  next() 
})

app.use("/"....)

結論、どんな形でもnext()が呼ばれればいいのかな?

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?