【问题标题】:Starting node js service on local在本地启动节点 js 服务
【发布时间】:2019-08-29 09:44:22
【问题描述】:

我有一个节点 js gradle 应用程序。我不确定如何在本地运行应用程序。

我已经完成了 gradle build (./gradlew) 和 npm run build(compile)。我所有的依赖都在node_modules

我有一个 server.ts 文件,其中包含除路由之外的服务器代码。

我的 package.json-

{
  "name": "app",
  "version": "..",
  "description": "",
  "main": "index.js",
  "types": "index.d.ts",
  "scripts": {
    "prepublish": "npm run build",
    "build": "tsc",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "async-child-process": "^1.1.1",
    ..
  },
  "devDependencies": {
    "@types/handlebars": "^4.0.36",
    "@types/node": "^8.10.45",
    "@types/pg-types": "^1.11.4"
  }
}

如何在服务器上运行项目。

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./build/js/",
        "sourceMap": false,
        "noImplicitAny": false,
        "module": "commonjs",
        "declaration":true,
        "target": "es2015"
    },
    "include": [
        "src/main/ts/**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

【问题讨论】:

  • @MarS 用 package.json 更新

标签: node.js typescript npm


【解决方案1】:

Node.js 不会运行 ts 代码。构建后它将在 dist 目录中的 js 代码(取决于 tsconf.json)。

在 package.json 中添加以下代码,运行npm run serve 启动服务器。

或转到 dist 目录并运行 node server.js

我在 GitHub 上创建了一个示例 check here

"scripts": {
    "serve": "npm run build && npm run start",
    "start": "node dist/server.js",
    "build": "tsc"
}

【讨论】:

  • 在我的问题中添加了 tsconfig。没有 dist 文件夹
  • @themaster 检查链接
猜你喜欢
  • 1970-01-01
  • 2019-07-29
  • 2022-12-14
  • 2020-11-10
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
  • 2018-05-28
  • 1970-01-01
相关资源
最近更新 更多