Javascript 从nodeJS服务器运行Angular 6时出错

Javascript 从nodeJS服务器运行Angular 6时出错,javascript,node.js,angular,typescript,Javascript,Node.js,Angular,Typescript,我的项目结构是 myApp- |-dist - |- myApp - |- index.html |- main.js |-server- |- app.js |-src- | - app | - assets | - index.html

我的项目结构是

myApp-
     |-dist -
             |- myApp -
                      |- index.html
                      |- main.js

     |-server- 
             |- app.js

     |-src-
             | - app
             | - assets
             | - index.html
             | - main.ts
我的
app.js
文件

var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var http = require('http');
var app = express();

var port = process.env.PORT || 3000;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));


app.use(express.static(path.join(__dirname, 'dist')));


app.get('/',(req,res)=> {
  res.sendFile(path.join(__dirname, '../dist/myApp/index.html'));
});

var server = http.createServer(app);

server.listen(port, ()=>{
  console.log('Server running at port ', port)
});
角度文件和默认文件相同

但它只显示了一个空白页。 我知道它正在到达
index.html
,因为它更改了index.html中标题的名称,但没有到达
app.component.html

index.html页面不可用

   <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>BtechApp</title>
      <base href="/BtechApp">

      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="image/x-icon" href="favicon.ico">
    </head>
    <body>
      <app-root></app-root>
    </body>
    </html>
但在我的例子中,路径是

dist -
     | - myApp -
               | - index.html

注意-我发现问题出在我的app.js文件中,你可以在下面查看我的答案。

index.html使用标记而不是文档的类型。因此,当node试图解析index.html时,它会得到第一个字符<,这就是它所抱怨的。放置html标记应该会有帮助。

我只是给index.html提供了错误的路径

因此,新的app.js将

app.use(express.static(__dirname + '/dist/newApp'));

app.get('/', (req,res)=>{
  res.sendFile(path.join(__dirname));
});

角度代码在哪里?控制台中有错误吗?@Clint在检查页面上显示
Uncaught SyntaxError:Unexpected token
听起来像是javascript的语法错误。对于问题中的内容,我们几乎无能为力。通常,无论如何,在angular cli中,dist文件夹是从src文件夹编译的代码所在的位置。您的index.html文件中明显缺少
script
元素,这使我相信编译过程中出现了问题。@Hereticsmonkey我使用
ng build
命令进行编译。我应该将该标记放在哪里?别忘了关闭文档末尾的html标记。我正在关闭index.html中的每个标记。你可以在上面看到。
dist -
     | - myApp -
               | - index.html
app.use(express.static(__dirname + '/dist/newApp'));

app.get('/', (req,res)=>{
  res.sendFile(path.join(__dirname));
});