Environment variables are used to store sensitive information, such as database credentials and API keys, outside of the application code. This makes it easier to manage and secure the application. Environment variables can be set using the .env file or directly in the shell. By utilizing environment variables, Node.js web hosting becomes more secure and manageable.