What is Express.js?

This is over simplifying it, but Express.js is to Node.js what Ruby on Rails or Sinatra is to Ruby. Express 3.x is a light-weight web application framework to help organize your web application into an MVC architecture on the server side. You can use a variety of choices for your templating language (like EJS, Jade, and Dust.js). You can then use a database like MongoDB with Mongoose (for modeling) to provide … Read more

Error: Can’t set headers after they are sent to the client

The res object in Express is a subclass of Node.js’s http.ServerResponse (read the http.js source). You are allowed to call res.setHeader(name, value) as often as you want until you call res.writeHead(statusCode). After writeHead, the headers are baked in and you can only call res.write(data), and finally res.end(data). The error “Error: Can’t set headers after they are sent.” means that you’re already in the Body or Finished … Read more

Client on Node.js: Uncaught ReferenceError: require is not defined

This is because require() does not exist in the browser/client-side JavaScript. Now you’re going to have to make some choices about your client-side JavaScript script management. You have three options: Use the <script> tag. Use a CommonJS implementation. It has synchronous dependencies like Node.js Use an asynchronous module definition (AMD) implementation. CommonJS client side-implementations include (most of them require a build step before you … Read more

Error: Can’t set headers after they are sent to the client

The res object in Express is a subclass of Node.js’s http.ServerResponse (read the http.js source). You are allowed to call res.setHeader(name, value) as often as you want until you call res.writeHead(statusCode). After writeHead, the headers are baked in and you can only call res.write(data), and finally res.end(data). The error “Error: Can’t set headers after they are sent.” means that you’re already in the Body or Finished … Read more

Client on Node.js: Uncaught ReferenceError: require is not defined

This is because require() does not exist in the browser/client-side JavaScript. Now you’re going to have to make some choices about your client-side JavaScript script management. You have three options: Use the <script> tag. Use a CommonJS implementation. It has synchronous dependencies like Node.js Use an asynchronous module definition (AMD) implementation. CommonJS client side-implementations include (most of them require a build step before you … Read more