Code won't run on my local server

Code won't run on my local server
0

#1

I’m working on the D3 Choropleth map project. I’ve been trying to make my map show on my local server and failed. So I decided to copy some code from stack overflow and see if it will work. The code is here:


This code works on codepen and jsfiddle but doesn’t work on my local server. Is there something I’m missing? Is there software that I need to install?
Please try to copy the code and run in on localhost to see if it works, so I can know why it works on your computer but not mine.


#2

have you included all dependencies which your project uses?


#3

The code on my text editor is the same as that of the codepen, and includes the external scripts for d3 version 4 and topojson version 2. Is there anything else I need?


#4

huh, it’s hard to tell without looking at the code… did you try to open dev tools and read the error message?


#5

The code is exactly the same as the one on codepen and it has no errors. Try and copy it on to your text editor and see if it runs.


#6

i believe you it’s the same… but with these limited information i can only make a guess… … dev tools is your best shot, if there are no errors in console of your browser, maybe you’re looking at the wrong url… i don’t know… are you running it on localhost?


#7

Yes its on localhost. I’ve checked dev tools and there are no errors, so I’m thinking there might be some software that I need for it to work, but I don’t know which software that is. I tried running this code for over an hour on localhost and only tried it on codepen once I got frustrated, only to find it runs on codepen, so my computer is the problem.


#8

what server are you using for localhost? apache, express? have you tried to run it directly from disk, for example file:///C:/path/to/your/project/pomodoroClock/index.html?


#9

localhost:3000. I’m using atom text editor so I launch the server from there. Running it directly from disk also hasn’t worked. I have no idea what apache and express are.


#10

text editor doesn’t matter here… then what are you using to run server? pure node or something else?


#11

I have nodejs installed. Maybe you should try it on yours so we can see if there’s a difference.


#12

i took a look at your code on codepen… if it’s exactly the same, then don’t forget to add header and body tags to your html file… after that, include css and d3 in that html… can you paste your server file code so i can take a look?


#13

The only thing that is different from the codepen code is html, since on codepen all I have to do is type the html body on the html section. Here it is:
style.css is the same as the css in codepen
script.js is the same as the javascript in codepen
for the html see the screenshot


#14

put <link rel="stylesheet" href="style.css" > before scripts… but it seems to me that you don’t have local server at all… at least from what i can see in this picture…


#15

even if i put the stylesheet before scripts it wont show.
This is what I see when I run localhost


#16

yeah, i saw the most recent screenshot…
try to enter in your browser that url from atom’s bar in the top left corner, can you it? that one which starts with C:\Users… and when you open it in the browser, go to index.html and tell me what do you see…

EDIT: oh i see now… ok server is working…


#17

please screenshot me the elements, it left one from console tab in dev tools…

EDIT: I think I know what the problem is…


#18


#19

expand me the <head>, I need to see that… maybe it’s problem in relative paths to your script.js


#20