Sending Files

A great helper method in Express is the sendfile(filepath) method on the Response object. sendfile() uses a single function call to do everything that needs to be done to send files to the client. Specifically, the sendfile() method does the following:

Image Sets the Content-Type header to the type based on file extension.

Image Sets other appropriate headers, such as Content-Length.

Image Sets the status of the response.

Sends the contents of the ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.