What does a colon mean on a directory in node js?

前端 未结 2 1974
星月不相逢
星月不相逢 2021-01-13 08:40

I\'m reading a book about nodejs/express and I\'m trying to reproduce the examples. I\'ve never seen a colon on a directory name, but I\'ve seen it a couple of times in this

2条回答
  •  忘掉有多难
    2021-01-13 09:01

    As SLaks stated, it's a URL pattern, the colon means that you want to receive the URL segments as parameter, here is an example

    app.get('/user/:id', function(request, response){
      response.send('user ' + request.params.id);
    });
    

    in this example, if you will send a get request to the URL www.server.com/user/mike, the request.params.id will be set to mike.

提交回复
热议问题