Skip to content

Instantly share code, notes, and snippets.

@dstevensio
Created August 31, 2012 16:20
Show Gist options
  • Save dstevensio/3555326 to your computer and use it in GitHub Desktop.
Save dstevensio/3555326 to your computer and use it in GitHub Desktop.
Hosting node.js web apps on Webfaction - path inconsequential
Suppose you set up a custom app (listening on port) with Webfaction and you are assigned port 34544.
Now, let's say your node app is deployed by pushing to github on your local machine and pulling it down to your webfaction server.
The actual location within the directory Webfaction's control panel set up for you is irrelevant, so when you clone your Git repo, it creates a subfolder within the created directory - so your node app isn't at the root. But it'll still work as long as you get the correct port:
example node app:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(34544, '127.0.0.1');
Let's say we call this file server.js and you named your webfaction app "mynodeapp" - it could be located in any of these paths:
~/webapps/mynodeapp/server.js
~/webapps/mynodeapp/My-Node-App/server.js
~/webapps/mynodeapp/repos/My-Node-App/server.js
And it will work, as long as the port specified in that listen() directive is the one assigned to the app when you set it up in the panel.
@netpoetica
Copy link

Thanks for this! Any idea why? I would imagine that if you don't implicity tell it what port and path you want, it would do it's own lookup and slowdown the process of getting to your content?

@dstevensio
Copy link
Author

Truthfully, I don't fully understand it. It's an idiom outside of the established norm for most of us when it comes to web development, where path is very relevant. But if we have an app that is listening on a port, and an application binds to that port (which is what happens when our node app fires up, it binds to 34544 in this case) then no lookup is happening, in the traditional definition that I believe we're sharing here.

"I will use the output of port X"
"I'm bound to port X"
"I will use you!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment