Express.js 在哪里? API?

发布于 2024-11-14 18:43:46 字数 592 浏览 0 评论 0原文

几天前就知道了node.js和express。我觉得他们确实很酷,但是还缺少一些东西。

我查看了官方网站,但它只指向 Connect 的 API。 但我找不到教我如何使用诸如expressHTTPServer.get()之类的简单函数的文档。

当然我读了nodejs的API,但是Express和Connect似乎对它们进行了很大的扩展。

例如,在 Express 官方网站中:

app = express.createServer();
app.get('/user/:id', function(req, res, next){
   loadUser(req.params.id, function(err, user){
     if (err)
       return next(err);
    res.send('Viewing user of csser.com ' + user.name);  }
   );
});

但遗憾的是,没有 API 文档告诉我有expressHTTPServer.get 以及它的回调参数是什么。

我喜欢阅读示例,但我确实需要一个 API 来学习新的语言/库/框架,有人可以帮忙吗?

have known node.js and express several days ago. I feel they are really cool, however, lacking of something.

I looked the official site, but it just point to Connect's API.
But I can't find a document which teach me how to use a simple function such as expressHTTPServer.get().

Of course I read the nodejs's API, but the Express and Connect seems to extend them very much.

For example, in Express official site:

app = express.createServer();
app.get('/user/:id', function(req, res, next){
   loadUser(req.params.id, function(err, user){
     if (err)
       return next(err);
    res.send('Viewing user of csser.com ' + user.name);  }
   );
});

But sadly, no API document talk me there is expressHTTPServer.get and what it's callback arguments are.

I like to read examples, but I really need an API to learn a new language/library/framework, anyone helps?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余生共白头 2024-11-21 18:43:46

以下是官方文档: http://expressjs.com/guide.html

另外,来源可以回答您的很多问题:https://github.com/visionmedia/express

Here are the official docs: http://expressjs.com/guide.html

Also, the source can answer a lot of your questions: https://github.com/visionmedia/express

明月松间行 2024-11-21 18:43:46

如果我正确理解你的问题,你想了解传递给回调的 req 和 res 参数的 API,对吧?

看看 http.ServerRequesthttp.ServerResponse

Express 本身使用 Connect,它使用标准 Node.js HTTP API。传递给回调的参数是所描述对象的猴子修补实例。

如果您希望请求由另一个中间件模块处理,则参数“next”是一个可以调用的函数。如果您想在处理程序中处理请求,这不需要打扰您。

If I understand your question correctly, you want to get to know the API of the req and res parameters passed to your callback, right?

Have a look at http.ServerRequest and http.ServerResponse

Express itself uses Connect which uses the standard Node.js HTTP API. The arguments passed to your callback are monkey patched instances of the described objects.

The Argument "next" is a function you can call if you wish that the request gets handled by another middleware module. If you want to handle the request within your handler, this doesn't need to bother you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文