NodeJS static file HTTP server
There are more efficient ways to do this. Now you are buffering the whole file content into memory, when you perform fs.readFile(...). I recommend that you use a readStream, that for example using fs.createReadStream(&lt;path&gt;), pipe it into res. This way you will begin sending the file content earlier, and stop wasting your node processes memory. Also consider moving require to the top of your code, it is a bad practice to call require from function body.