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.
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.
Related Posts:
- Start script missing error when running npm start
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- TypeError: Router.use() requires middleware function but got a Object
- Express error – TypeError: Router.use() requires middleware function but got a Object
- Cannot GET / Nodejs Error
- What is NODE_ENV and how to use it in Express?
- TypeError: Router.use() requires middleware function but got a Object
- What does “res.render” do, and what does the html file look like?
- stop all instances of node.js server
- Express Render not working return error: No default engine was specified and no extension was provided
- TypeError: Router.use() requires middleware function but got a Object
- Express error – TypeError: Router.use() requires middleware function but got a Object
- Expressjs / Node.js – res.redirect() not loading page
- MissingSchemaError: Schema hasn’t been registered for model “User”
- Make Axios send cookies in its requests automatically
- How do I remove documents using Node.js Mongoose?
- Error: ENOENT: no such file or directory, stat ‘/public/main.html’ at Error (native)
- Error: Cannot find module html
- How to access the request body when POSTing using Node.js and Express?
- TypeError: res.status is not a function
- TypeError: res.json is not a function
- How can I use webpack with express?
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general? [closed]
- How to get all place details from a Place Details Request using Google Places API Web Service?
- SyntaxError: Unexpected token o in JSON at position 1
- Babel 6 regeneratorRuntime is not defined
- SyntaxError: Unexpected token o in JSON at position 1
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general?
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- require is not defined? Node.js
- Node.js heap out of memory
- Reactjs – Form input validation
- await is only valid in async function
- await is only valid in async function
- SyntaxError: Unexpected token o in JSON at position 1
- Heroku: “No default language could be detected for this app” error thrown for node app
- NPM ELIFECYCLE error – using node server.js command
- ReferenceError: fetch is not defined
- AngularJS- Login and Authentication in each route and controller
- Node.js – SyntaxError: Unexpected token import
- SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag
- TypeError: Cannot read property ‘then’ of undefined
- Invalid shorthand property initializer
- nodejs – error self signed certificate in certificate chain
- How to Create simple drag and Drop in angularjs
- Working with $scope.$emit and $scope.$on
- Using Node.js require vs. ES6 import/export
- npm – EPERM: operation not permitted on Windows
- How can I mock an ES6 module import using Jest?
- SyntaxError: Unexpected token o in JSON at position 1
- AngularJS : Factory and Service?
- AJAX response error: net::ERR_EMPTY_RESPONSE
- SyntaxError: Cannot use import statement outside a module
- How to determine the installed webpack version
- node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
- Blocked script execution in because the document’s frame is sandboxed – Angular application
- Node update a specific package
- How to properly export an ES6 class in Node 4?
- Failed to compile. Module not found: Can’t resolve ‘react-router-dom’
- Angular JS Uncaught Error: [$injector:modulerr]
- Use of $parse in angular js
- Convert Array to Object
- How to set the id attribute of a HTML element dynamically with angularjs (1.x)?
- Cannot find module ‘internal/fs’ after upgrading to node 7
- Using $setValidity inside a Controller
- How can I group data with an Angular filter?
- node-request – Getting error “SSL23_GET_SERVER_HELLO:unknown protocol”
- Why does JSHint throw a warning if I am using const?
- Difference between “module.exports” and “exports” in the CommonJs Module System
- Error: [ng:areq] from angular controller
- Understanding the ngRepeat ‘track by’ expression
- why angularjs ng-repeat not working
- How to connect signalR from angularJs
- Array Mapping in AngularJs
- Maximum call stack size exceeded on npm install
- AngularJS errors: Blocked loading resource from url not allowed by $sceDelegate policy
- How do you completely remove Ionic and Cordova installation from mac?
- Error: listen EACCES 0.0.0.0:80 OSx Node.js
- How to sort in mongoose?
- How do you serve a file for download with AngularJS or Javascript?
- Failed to execute ‘postMessage’ on ‘DOMWindow’: https://www.youtube.com !== http://localhost:9000
- What counts as CPU Intensive tasks (eg. sorting, searching etc?)
- How to redirect to another page using AngularJS?
- How to convert binary string to decimal?
- events.js: 141 throw er; // Unhandled ‘error’ event
- Why is this simple AngularJS ng-show not working?
- How to disable auto-start of “Node.js: Server-side JavaScript” when using Adobe Dreamweaver?
- How to enable CORS in AngularJs
- parsing JSONP $http.jsonp() response in angular.js
- “React.Children.only expected to receive a single React element child” error when putting
and in a - What is the cause for “angular is not defined”
- $http.get(…).success is not a function
- Unexpected token < in first line of HTML
- ngular is automatically adding ‘ng-invalid’ class on ‘required’ fields
- How to fix “TypeError: Right-hand side of ‘instanceof’ is not callable” when I use another module class?
- DeprecationWarning: Calling an asynchronous function without callback is deprecated. – how to find where the “function:” is?
- Is there a way to create interfaces in ES6 / Node 4?