Serving files

Keyboard Shortcuts

When a user requests a resource, it will be delivered from your server. Once you set up a web server, you will likely want to use it to send files. In this Node.js training video, Alex Banks will demonstrate how to create read streams and create a very customizable content server.

- One of the most important features of web servers…is the ability to serve files.…Usually, the first thing we learn about Apache or IIS is…where to put our HTML, CSS, images and other assets…that we want that web server to serve.…Now, with Node.js, we actually have to build the web server.…In order to build a web server, we're going to have to…use the https module in conjunction with the fs module.…When we request a file, we are going to have to use…the file system to load that file, and then we can use…the HTTP module to respond with its contents.…

Let's build a file server.…Let's go ahead and navigate to our files.…You will notice that there is a fileserver.js,…the empty JavaScript file where we're going to build…this fileserver, as well as a public folder.…And in the public folder, we have a .jpg file,…we have a styles.css, and we also have an index.html page…that includes the .jpg and the stylesheet referenced…right inside of the HTML.…So let's go ahead and serve that index file,…and we will do so in our fileserver.js file.…

Resume Transcript Auto-Scroll

Author

Updated

8/31/2017

Released

12/11/2015

Node.js is a powerful tool for controlling servers, building web applications, and creating event-driven programs. And it takes JavaScript—a language familiar to all web developers—out of the browser. With Node.js, you can build applications that run on your laptop or even the cloud. Learn the essentials of Node.js and start creating your own JavaScript applications in this introductory training course.

Alex Banks shows how to install Node.js on a Mac or PC and work with the Node.js core: the global object, event loop, http module, and file system. Then he covers reading and writing data, streaming data, making http requests, and working with the node package manager (npm). In the final chapters, he shows how to start sessions on web servers, communicate with web servers and clients with WebSockets, use the Express framework to develop applications, and test and debug Node.js code. Want to speed up your Node.js workflow? Check out the tutorials on automating tasks with Grunt and npm scripts.

Topics include:

What is Node.js?

Installing Node.js

Understanding the global object and global timing

Importing the core modules

Handling events

Creating child processes

Reading, writing, and removing files

Working with file streams

Making http requests

Serving files and JSON data

Installing npm, the node package manager

Working with Express, the web server framework

Using WebSockets

Testing and debugging Node.js code

Working with Grunt and Browserify

Automating tasks with npm scripts

Skill Level Intermediate

6h 22m

Duration

1,327,996

Views

Show MoreShow Less

Q: This course was updated on 09/06/2017. What changed?

A: New videos were added that cover upgrading Node. In addition, the following topic was updated: debugging with npm.