简体   繁体   English

将app作为http.createServer的参数

[英]Express app as argument of http.createServer

When I want to use express.Application as argument of http.createServer I have this error: 当我想使用express.Application作为http.createServer的参数时,我有这个错误:

error TS2345: Argument of type 'Application' is not assignable to parameter of type '(request: IncomingMessage, response: ServerResponse) => void'.

My code: 我的代码:

import * as express from "express"
let app: express.Application = express();
...
import * as http from "http"
let httpServer = http.createServer(app);
httpServer.listen(process.env.HTTP_PORT, (): void => {
    console.log(`HTTP Listen on ${process.env.HTTP_PORT}`)
});

typings.json: typings.json:

{
  "dependencies": {
    "body-parser": "registry:npm/body-parser#1.15.2+20160815132839",
    "express": "registry:npm/express#4.14.0+20160911114220"
  },
  "globalDependencies": {
    "dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
    "errorhandler": "registry:dt/errorhandler#0.0.0+20160316155526",
    "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160914120416",
    "method-override": "registry:dt/method-override#0.0.0+20160317120654",
    "morgan": "registry:dt/morgan#1.7.0+20160524142355",
    "node": "registry:dt/node#6.0.0+20160921192128"
  }
}

I solve it. 我解决了 Just need to update typings. 只需要更新打字。 My current typings.json file: 我目前的typings.json文件:

{
  "globalDependencies": {
    "dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
    "errorhandler": "registry:dt/errorhandler#0.0.0+20160316155526",
    "express": "registry:dt/express#4.0.0+20160708185218",
    "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160916114806",
    "method-override": "registry:dt/method-override#0.0.0+20160317120654",
    "morgan": "registry:dt/morgan#1.7.0+20160524142355",
    "node": "registry:dt/node#6.0.0+20160921192128",
    "serve-favicon": "registry:dt/serve-favicon#0.0.0+20160316155526"
  },
  "dependencies": {
    "body-parser": "registry:npm/body-parser#1.15.2+20160815132839",
    "serve-static": "registry:npm/serve-static#1.11.1+20160810053450"
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM