节点js目录中的冒号是什么意思? [英] What does a colon mean on a directory in node js?

查看:77
本文介绍了节点js目录中的冒号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一本有关nodejs / express的书,并且试图重现这些示例。
我从未在目录名称上看到冒号,但在本书中已经看到过几次了。你能告诉我这是什么意思吗?

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 book. Could you tell me what it means?

这是我看到的示例:

app.post('/contest/vacation-photo/:year/:month', function(req, res){


推荐答案

正如SLaks所说,这是一个URL模式,冒号表示您希望接收URL段作为参数,这是一个示例

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);
});

在此示例中,如果您会将获取请求发送到URL www.server.com/user/mike,request.params.id将设置为mike。

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.

这篇关于节点js目录中的冒号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆