codeforhuntsville / Frontier

A civic app for finding whats near me
http://codeforhuntsville.com/
MIT License
9 stars 7 forks source link

Update README.md with developer note #41

Closed TomCasaletto closed 9 years ago

TomCasaletto commented 9 years ago

At last hack night, worked with @Nedlinin on referencing local server for faster developer work flow.

Nedlinin commented 9 years ago

@TomCasaletto : must have been someone else. I didn't make it last week :(

Whomever it was can surely speak up though. Or I can write some instructions on how I have mine setup.

I've been considering adding in gulp + live reload but with the makefile already in place I'm not sure its worth it. If its something people like I can throw it together.

TomCasaletto commented 9 years ago

Thanks @Nedlinin

I think it was a new Chris. Too many Chriseses!

Anyway, was using this to get a feel for how the github workflow goes. I was going to add a note to the readme about accessing localhost:8080 instead of the ngrok server. Just getting my feet wet.

TomCasaletto commented 9 years ago

@Nedlinin : At hack night I was able to access the local server via localhost:8080 but now I get "Unable to connect". When I bring up the Frontier server, my console says "listening on port 8080" but when I netstat -tulpn it there is not a listener at 8080. Any ideas?

Nedlinin commented 9 years ago

@TomCasaletto : Not off of the top of my head. We detect the port number from the config files and only output the "listening on " message if the server detects it has successfully started.

Are you sure you're running node index.js on the local box and not SSHd in somewhere else?

Nedlinin commented 9 years ago

For reference, on master branch I do.

cd Frontier
make
node index.js

Output of last command is:

nedlinin@nedlinin:~/Frontier$ node index.js
listening on port 8080

And netstat shows:

nedlinin@nedlinin:~$ sudo netstat -tulpn | grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      7275/node
TomCasaletto commented 9 years ago

@Nedlinin : I get the following when I try that ... Successfully built 4c2559e5cbc9 tom@tom-Inspiron-5737:~/etc/Frontier$ node index.js

module.js:340 throw err; ^ Error: Cannot find module 'express' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object. (/home/tom/etc/Frontier/lib/server/index.js:2:15) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) tom@tom-Inspiron-5737:~/etc/Frontier$ git branch

Nedlinin commented 9 years ago

Looks like you need to do an

npm install

You don't appear to have the express module installed so it's failing to run.

You might also want to do an

npm install -g webpack

to get a global copy of webpack for use.

TomCasaletto commented 9 years ago

Thanks for the tips.

Yes, I wiped my install from Wednesday and started from scratch and skipped the npm install step. After doing that, and setting an environment variable for my GOOGLE_PLACES_API_KEY, node does come up:

tom@tom-Inspiron-5737:~/etc/Frontier$ node index.js listening on port 8080

And it appears to be waiting for requests:

tom@tom-Inspiron-5737:~/etc/Frontier$ netstat -tulpn |grep 8080 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 19693/node

But when I open a web page to localhost:8080 it just hangs there. When I launch the server via 'make run...' it says it is listening on 8080 but netstat says it aint. Though I am able to access the server in this mode via ngrok

TomCasaletto commented 9 years ago

Ok, got it working: a) set GOOGLE_PLACES_API_KEY environment variable b) npm start c) from browser open localhost:8080

Nedlinin commented 9 years ago

Missed your last message. But yea. Npm start runs webpack.

If you want to launch it manually it'd be

webpack
node index.js

But npm start is essentially a shortcut and you might as well go that route.

Nedlinin commented 9 years ago

Now that I'm at my computer I can better explain.

So, npm relies on package.json to know what to do.

https://github.com/codeforhuntsville/Frontier/blob/master/package.json#L9

This line is inside the scripts portion of the file. Anything in here can be run with the npm notation. In our case, it sets up an environment variable and starts webpack then runs nodejs to serve the resulting files out.

Hence you why could manually run

webpack
nodejs index.js 

to get the same result.

Any errors in the vein of

Error: Cannot find module 'express'

is essentially saying you need to do npm install to obtain all modules you need for the project. They will be listed in package.json under dependencies and devDependencies. Dependencies are things required to run the project, devDependencies are things required to build the project.

Anyway, glad you got things working! Sorry I was slow on the responses -- family is in town this week!

chadxz commented 9 years ago

Closed by #42