在js文件中调用Express.js的函数
我在Express.js中有一个函数,使用Node.js:
app.post("/checkExistsSpecific", function (req, res) { // do some code }
我有另一个function
app.post("/checkExistsGeneral", function (req, res) { // do some code // In this stage, I want to call /checkExistsSpecific API call }
有没有办法从app.post("/checkExistsGeneral"..)
调用app.post("/checkExistsGeneral"..)
而不使用HTTP调用?
为了做到这一点,我认为你应该使用命名函数作为你的POSTcallback,而不是你现在拥有的匿名。 这样,你可以从你需要的地方引用它们。
就像是:
function checkExistsSpecific(req, res){ // do some code } app.post("/checkExistsSpecific", checkExistsSpecific); app.post("/checkExistsGeneral", function (req, res) { // do some code // In this stage, I want to call /checkExistsSpecific API call checkExistsSpecific(req, res); }
最好。
如果你只是想以正常的方式调用函数:
function beingCalled (req, res) { } app.post("/checkExistsSpecific", beingCalled ); app.post("/checkExistsGeneral", function (req, res) { beingCalled (req,res); }
要么
response.redirect("/checkExistsSpecific"..)
是你正在寻找(可能)。
这会将你的http调用redirect到checkExistsSpecific
路由
- 如何让Node.JS Express只听localhost?
- Angularjs CORS与Node,Express,Oauth2和Passport有关
- mongooseerror handling
- Node.js表示应用程序caching/缓慢页面加载(swig模板引擎)
- Express / NodeJS:stderr:错误:请求实体太大
- 内容处置:附件不触发下载对话框
- (Node JS + Express)如何渲染一个在/ views / subfolder /里面的文件?
- 如何在centos 6.4 virtualbox客户端上用express来设置和configurationnode.js到nginx反向代理?
- node.js进程的内存消耗不断增加