语法错误:预期前pression,拿到了'<' [英] SyntaxError: expected expression, got '<'

查看:197
本文介绍了语法错误:预期前pression,拿到了'<'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

语法错误:预期前pression,拿到了'< 当我执行以下节点code错误控制台

I got SyntaxError: expected expression, got '<' error in the console when i'm executing following node code

var express = require('express');
var app = express();
app.all('*', function (req, res) {
  res.sendFile(__dirname+'/index.html') /* <= Where my ng-view is located */
})
var server = app.listen(3000, function () {
  var host = server.address().address
  var port = server.address().port
})

错误:

Error :

我采用了棱角分明的js和它的文件夹结构,像波纹管

I'm using Angular Js and it's folder structure like bellow

什么是我在这里丢失?

What's I’m missing here ?

推荐答案

这code:

app.all('*', function (req, res) {
  res.sendFile(__dirname+'/index.html') /* <= Where my ng-view is located */
})

告诉防爆preSS,不管什么浏览器的请求,服务器应该返回 index.html的。因此,当浏览器请求JavaScript文件如 jQuery的-xyzmain.js angular.min.js ,您的服务器返回的内容的index.html ,与&启动LT;!DOCTYPE HTML&GT; ,这会导致JavaScript错误。

tells Express that no matter what the browser requests, your server should return index.html. So when the browser requests JavaScript files like jquery-x.y.z.main.js or angular.min.js, your server is returning the contents of index.html, which start with <!DOCTYPE html>, which causes the JavaScript error.

您code应该寻找的请求,以确定要发送的文件回来,和/或你应该使用不同的路径与模式 app.all 。详情请参阅路由指南

Your code inside the callback should be looking at the request to determine which file to send back, and/or you should be using a different path pattern with app.all. See the routing guide for details.

这篇关于语法错误:预期前pression,拿到了'&LT;'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆