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 to make a discord bot create an invite for every server it joins?
- map function for objects (instead of arrays)
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general? [closed]
- How to you store data for each discord user in the discord server?
- 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
- TypeError: Converting circular structure to JSON in nodejs
- Babel 7 – ReferenceError: regeneratorRuntime is not defined
- How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- 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
- How to set NODE_ENV to production/development in OS X
- await is only valid in async function
- Heroku: “No default language could be detected for this app” error thrown for node app
- SyntaxError: Unexpected token o in JSON at position 1
- Heroku: “No default language could be detected for this app” error thrown for node app
- SyntaxError: Unexpected token o in JSON at position 1
- How to obtain username from Promise
? - NPM ELIFECYCLE error – using node server.js command
- Node.js – SyntaxError: Unexpected token import
- ReferenceError: fetch is not defined
- AngularJS- Login and Authentication in each route and controller
- ‘react-scripts’ is not recognized as an internal or external command
- After $npm install, Getting Error: Cannot find module ‘../lib/utils/unsupported.js’
- 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
- What’s the source of Error: getaddrinfo EAI_AGAIN?
- How to Create simple drag and Drop in angularjs
- Working with $scope.$emit and $scope.$on
- Using Node.js require vs. ES6 import/export
- ReferenceError : window is not defined at object.
Node.js - Why is process.env.NODE_ENV undefined?
- Node.js Port 3000 already in use but it actually isn’t?
- Unable to verify leaf signature
- npm – EPERM: operation not permitted on Windows
- In angularjs we are having ng-disabled directive, why ng-enabled directive is not provided by the framework as we are having ng-show and ng-hide
- How can I mock an ES6 module import using Jest?
- Regular expression : match either of two conditions?
- SyntaxError: Unexpected token o in JSON at position 1
- AngularJS : Factory and Service?
- AJAX response error: net::ERR_EMPTY_RESPONSE
- Give a value to an ng-model=”searchText” input based on list item clicked in Angular JS
- How to use npm jquery module?
- Node.js Error: connect ECONNREFUSED
- TypeError: app.use() requires middleware functions
- TypeError: Cannot read property ‘get’ of undefined on AngularJS
- No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’
- SyntaxError: Cannot use import statement outside a module
- Node.js document is not defined
- How to handle ETIMEDOUT error?
- How to determine the installed webpack version
- node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
- XMLHttpRequest module not defined/found
- 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?
- Using async/await with a forEach loop
- Why is my asynchronous function returning Promise {
} instead of a value? - Failed to compile. Module not found: Can’t resolve ‘react-router-dom’
- NodeJs : TypeError: require(…) is not a function
- Angular JS Uncaught Error: [$injector:modulerr]
- What is the difference between node.js and io.js?
- module.exports vs exports in Node.js
- Use of $parse in angular js
- Convert Array to Object