SyntaxError: expected expression, got '<'

0 votes

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
})
Jun 2 in Java-Script by kartik
• 15,440 points
59 views

1 answer to this question.

0 votes

Hii @kartik,

This code:

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

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.

Hope it helps!!

answered Jun 2 by Niroj
• 32,200 points

Related Questions In Java-Script

0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 32,200 points
810 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 32,200 points
82 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 32,200 points
94 views
0 votes
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 32,200 points
434 views
0 votes
1 answer

How do you access the matched groups in a JavaScript regular expression?

Hello, Here’s a method you can use to ...READ MORE

answered May 28 in Java-Script by Niroj
• 32,200 points
28 views
0 votes
1 answer

Solidity ParserError: Expected identifier but got '='

Hey, the solidity grammar doesn't allow assignments ...READ MORE

answered Oct 9, 2018 in Blockchain by Omkar
• 69,040 points
1,023 views
0 votes
1 answer

Truffle Compile failing, ParserError: Expected token LParen got Identifier function

Your parentheses are mismatched. pragma solidity ^0.4.17; import "truffle/Assert.sol"; import ...READ MORE

answered Oct 9, 2018 in Blockchain by Omkar
• 69,040 points
577 views
0 votes
1 answer

Python error "TypeError: range() integer end argument expected, got numpy.float64."

Hi @Kashish, try something like this: for i ...READ MORE

answered May 27, 2019 in Python by Harish
565 views
0 votes
1 answer

How to solve expected response code 220 but got code “”, with message “” in Laravel?

Hii @kartik, if you are using Swift Mailer: ...READ MORE

answered Mar 31 in Laravel by Niroj
• 32,200 points
1,707 views
0 votes
1 answer