Tag: express

  • Nodejs 413 request entity too large error

    There are several ways to resolve this issue. First, you should check with your hosting provider to see what settings they recommend. Second, you can try increasing the memory limit on your web server. Third, you can use a different method to upload the file instead of using FTP (File Transfer Protocol). Finally, you can split up the file into smaller parts and upload them one at a time.

    (more…)

  • Access query string parameters with Express and Node.js

    Passing data through the URL is a very common practice. As you can see with the URLs on my website, I pass – what I call – a slug of my post title in the URL. In this case: access-query-string-parameters-with-express-and-node-js. With this data I can figure out dynamically what blog post to show. Another common way is to use query string parameters such as ?id=1. There are two common ways that I perform this using Express and Node.js.

    (more…)

  • Solving No Access-Control-Allow-Origin with Node js and Express

    If you are receiving an error similar to XMLHttpRequest cannot load localhost:3000. No Access-Control-Allow-Origin header is present on the requested resource. Origin localhost:8888 is therefore not allowed access. This typically implies that you need to enable CORS on your Node js server that is running Express as the web server. Example code below.

    (more…)

  • Cannot set headers after they are sent to the client

    When you are using Node.js with Express and you’ve received the dreaded error [err_http_headers_sent]: cannot set headers after they are sent to the client where do you even begin with err_http_headers_sent’. This article will explore common causes of this error, such as calling res.writeHead, res.write, or res.redirect.

    A problem occurs when servers send out headers after the message has been received by the client. Node JS applications send multiple responses to the same request – eg. calling the request twice instead of a single request with one response res.send headers.

    (more…)

  • Uncaught ReferenceError: require is not defined

    When you’re first starting out with Node js, it might be a bit confusing because you are most likely accustomed to writing JavaScript code for the web browser. When Node js is the server, the syntax is similar but there are a few differences around how other JavaScript files and modules are included. When writing on the server side you may include files as follows: require(‘./mysharedfile’);.

    (more…)