When you're working on a site or web app, there will be times when you need to test files as if they were being served from a remote web server, similar to how they are when you browse the web normally.
If you don't have your own server, or just want to test files locally, you can set up a local web server on your computer to simulate one to do the job, and this tutorial is here to teach you how.
Prerequisites
- Node and NPM installed. If you don't have them installed, follow our how to install Node guide.
Install http-server
With Node and NPM installed, we can move forward and install the Node package called http-server, which is a simple zero-configuration HTTP server that serves up static files.
BASHnpm install http-server -g
This command will install it on your computer globally so you can use it anywhere.
Therefore, after you have navigated to your folder via the command line, start the server using this command:
BASHhttp-server -o
If successful, you should see something similar to this:
BASHhttp-server -o
Starting up http-server, serving ./
Available on:
http://192.168.1.8:8080
http://127.0.0.1:8080
Hit CTRL-C to stop the server
Upon seeing this, a browser window should have opened for you automatically, but if not, you can manually head to http://127.0.0.1:8080
to see the folder that you used the command on being served.
Happy coding! 😄
Resources
- How to Set Up Cron Jobs in Linux
- Best Visual Studio Code Extensions for 2022
- How to build a Discord bot using TypeScript
- How to deploy a MySQL Server using Docker
- How to deploy an Express app using Docker
- Learn how to use v-model with a custom Vue component
- Getting Started with Handlebars.js
- Getting Started with Moment.js
- Creating a Twitter bot with Node.js
- Building a Real-Time Note-Taking App with Vue and Firebase
- Getting Started with Vuex: Managing State in Vue
- Getting Started with Moon.js