Follow @endyourif rss Facebook LinkedIn

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

Published on Feb 24, 2020

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.

Uncaught ReferenceError: require is not defined

Published on Feb 23, 2020

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');.

Access query string parameters with Express and Node.js

Published on Feb 15, 2020

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.

If you are not already familiar with Express you can read my article on setting up Express with Node.js before you dive into this blog.

Can't set headers after they are sent

Published on Feb 15, 2020

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

Setup routes in Node.js with Express.js and Jade with controllers, models, and views

Published on Jul 14, 2019

I like the structure of Model View Controller (MVC) and I wanted to apply it to my Node.js projects.

I've written previous articles about Node using Jade Templates with Express, but I didn't go into much details about code organization; let's do that now.

Node using Jade Templates with Express

Published on Oct 8, 2012

My First Node Application

Published on Oct 4, 2012