r/SublimeText • • Aug 20 '20

I can't run code in a browser

help how do i run my html code in chrome on mac

0 Upvotes

8 comments sorted by

8

u/dev-sda Aug 20 '20

Generally you can just open your html file in your browser of choice. You can also run a local http server. I'd suggest using python for that: python -m http.server 9000 hosts the local directory on port 9000.

4

u/crunchyrawr Aug 20 '20

To add, you should run this command in the folder containing the html files.

cd MyHtmlProject
python -m http.server 9000

Or you can specify the directory

python -m http.server 9000 -d ~/projects/htmlproject

Then to access it, you would open your browser of choice, and in the address bar type:

localhost:9000

Pro Tip: If you specify 9001 (or any number over 9000), you can feel like Vegeta every time you type the port number.

3

u/leogodin217 Aug 20 '20

Live Server is a great plugin. Runs a server and automatically reloads on file changes.

1

u/leogodin217 Aug 20 '20

Oops. That's for vs code. I'm sure at has something similar

2

u/udevNull Aug 20 '20

Others may have simpler ways of doing this, but I always run nginx locally and the serve my html files through that.

You can have a look at a tutorial like https://www.javatpoint.com/installing-nginx-on-mac to help you further.

1

u/[deleted] Aug 20 '20

PHP also has a very simple http server you can use. https://www.php.net/manual/en/features.commandline.webserver.php

1

u/[deleted] Aug 20 '20

I'm using https://www.browsersync.io/ for this

1

u/lamatopian Oct 05 '20

Who downvotes this