Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Friday, 27 January 2012

Setting up my Node.js solution in Cloud9 IDE

Now where do we go after we have a brand new toy.. I just installed Cloud9 IDE.. see how-to install cloud9 here.

I want to setup a quick web app (really, really quick). I will time it.

00:00 - Get all my favourite (sounding) node modules from npm (presume you have npm) then use...
npm install  


See all the goodies I got.. note espresso took some time. Also look them up at http://search.npmjs.org/#/ 

00:09 - I had to install mongodb separately using (can also go here ..)

sudo apt-get install mongodb
00:18 - Created a folder at ~/devroot/MongoDb/data/db for my MongoDb instances. Now to run the db server..
mongod --port 9080 --objcheck --dbpath "devroot/MongoDb/data/db" --directoryperdb --rest
Note: --rest == RestApi, --directoryperdb == create a new dir for each new db's files
Success == MongoDb web console at http://127.0.0.1:10080/ (not so sure about the port, but trust that the mongod startup script should tell you your magic port number)



00:22 - Try out the mongodb server quickly...


mongo 
db.foo.save( some json object here );
db.foo.find()
 00:24 - setup that web app... hmm
Ok. Make sure you have done a global install of express using
sudo npm install -g express 
00:26 -  Use express to setup your solution structure inside your project root
sudo express  
cd   
npm install 
Note: this  installs default packages only so I had to get other ones here by
npm install
It uses  the cache (304) so it does not waste your time. I have now installed,
ejs, mongoose, colors.. (see list above)

Lets setup some routing .. see a good guide on expressjs here .. i am not re-inventing this.

Should be easy enough from here... good luck!


Node.js and Installing Cloud9 IDE

I am a bit infatuated with node.js at the moment and the whole real-time web thing. So trying to get it going on my machine. Why??? A.) I love javascript. B.) I love javascript. Always have. Never in secret. Been glared at for writing jQuery apps, etc. I have done all the other languages too (C#, java... respect.. they've paid my wages).

So... I have been at this for a whole day... phew! Tried on windows (gave up!) and now on Ubuntu. Need to go back to the mac (yes, I admit, the war is now over). I am lazy, I like simple kits, but I like a working IDE, debugger, etc. So I hunted around and found a few...

  • WebStorm (from JetBrains and they still make that super ReSharper VS-addin)
  • Cloud9 IDE - a nodejs based web IDE - how cool.. and open-source so you can run it on your box
WebStorm was simple enough install, could find all the modules but I could not get the debugger going. Anyone good with this, please ping me at kenn9j.at.gmail.com :) 

Cloud9 IDE was not simple to get installed. Too many rig-ma-roles... but it kicked in.. and here is how...
  • Go to http://gratdevel.blogspot.com/2011/03/setting-up-cloud9-on-ubuntu-1010-32-bit.html it says most of it.. (forget windows for now)
  • If you are running a 32-bit Ubuntu on 64-bit windows vmware like me.. all will not go well. So at some point you will get... "error while loading shared libraries: libssl.so.0.9.8: cannot open shared object file: No such file or directory" 
  • Fix it with - sudo apt-get install libssl0.9.8 
  • Start cloud9.. point to your project folder and it starts up in the ide.. in your default browser... :) smile... 
path-to-node-v4-build path-to-cloud9.js -w path-to-your-project -a x-www-browser 
~/cloud9/support/node-builds-v4/node-linux32 ~/cloud9/bin/cloud9.js -w ~/devroot/Nodey -a x-www-browser 

  • Add a little app.js file with a server in there like see above. Hit run (will have to configure first time so point to your app.js) 
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(3001, "0.0.0.0");
  • Enjoy! It's a bit slow on my vm but it can debug. (can always two-time with geany)