NodeJS @ ACS

1,718 views

Published on

Intro to the use of nodejs in ACS.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,718
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

NodeJS @ ACS

  1. 1. Node ACSMauro Parra-Mirandamauropm@gmail.com
  2. 2. AgendaIntroductionNodeJSFeaturesExamples
  3. 3. IntroductionFixed set of features in the ACS: checkins, post insocial net works, user administration, etc.Customers with needs out of that universe were akind of lost, since they have to provide their ownwebservices for custom stuff.Customers are not that good in setting upwebservices that escalate; or setup servers ingeneral.
  4. 4. SolutionACS was already providing a nice escalatinginfrastructure; the natural step was to extend thatser vice to a custom small/micro programs.Node JS was the selected technology to do the bridgebet ween the customer and the ACS, with superescalating power (vitamins added).Think of ACS as a Meta Cloud Services Provider,with zero server configuration time.
  5. 5. NodeJS“Node.js is an evented I/O framework for the V8JavaScript engine. It is intended for writingscalable net work programs such as web servers.” -Wikipedia.Who uses NodeJS? - Yammer, Proxlet, Bocoup, Yahoo,Walmart, Appcelerator :-)Niceties: Parallel execution, event driven, mongodbsupport, etc.
  6. 6. FeaturesCluster, crypto, dns, events, file system, http, https,modules, OS, Path, Process, readline, query strings,mongodb, timers, strings, tls/ssl, udp/datagram,utilities, zlib.You can use modules from the nodejs world, such as:http://blog.nodejitsu.com/6-must-have-nodejs-modulesxml2js: if you are using old webservices, you caneasily transform xml responses into javascriptobjects with this module. Think SOAP and stuff.
  7. 7. Setupinstall (from terminal in mac):$ sudo npm install -g acssetup (from terminal in mac):$ acs loginCreate a new app (from terminal in mac):$ acs new myappthis will create a directory myapp w/ your newapp
  8. 8. Edit your appGo to your directory myapp. Inside you will findmyapp.js. Edit and add this:api.index = function(req, res) { res.text(Hello, world!); logger.info(This is an info message. + new Date());}Save it.
  9. 9. Running your app locally acs run -d myapp Go to http://localhost:8080 to see your app running locally. If you are running jenkins, your app will use other port (Jenkins uses 8080 by default), so you will likely end in 8081 port.
  10. 10. Running your app in ACS acs publish -d myapp You will see your app running at http://<appid>.cloudservices.appcelerator.com It’s like having a Heroku in appc.
  11. 11. ServiceThe app now has one service (or a single endpoint)called api.index. The args are “Express framework”Request and Response ObjectsI.e. we are running express. Check more about ithere: http:/ /expressjs.com/You can add more services, with “ add”. acsacs add <name>You will expose this new service in t wo ways. Onepublic at: <app_url>/<name> and one in the code byapi.<name>
  12. 12. ModulesYou can use any nodejs modules within your app,using npm.You will need to list the modules you are using(dependencies) in the package.json file. So, when youdeploy the app (either locally or in the ACSinfrastructure), the modules will be installed in yourrunning instance.Besides the Node modules, you will have the loggerfunction for log and the builtin ACS library forcalling the ACS services.
  13. 13. Big fat example Check this call to the ACS login - user level Call to ACS PlacesYou can call any of the functions in ACS api!
  14. 14. Real problem - Escalate Escalate - This is the real issue. You will need something that will escalate properly and easily. Now, with NodeJS and ACS, you can escalate your webservices. Which, usually, will depend on a database. You now will have access to MongoDB - i.e., this next generation non-relational db. Think of mongodb as a db that will store objects instead of rows and columns - forget the excel type of order, get into a objects.
  15. 15. Setup mongodbCreate an app.Add mongodb as dependency in the package.json:"dependencies": { "mongodb": ">=1.1.6"},
  16. 16. Open connection to mongodb
  17. 17. Insert a record
  18. 18. Query a record
  19. 19. MongooseModule to provide ORM-alike features to NodeJS.This is, will abstract the objects from yourJavascript to MongoDB records easily.https://github.com/learnboost/mongoose/
  20. 20. NodeJS - how we escale? You have a service, with a single point of entry (like url/ser vice). In order to not block the server, you will need a request handler (worker) that will actually do the job, freeing the service to continue into listen mode. the request handler will actually implement the steps to do the processing - this is how you escalate. Forkity Fork!** sorry, i used to be a linux guy - fork processes
  21. 21. ResourcesNode Beginner - http://www.nodebeginner.orgAppc Blog - http://developer.appcelerator.com/blog/2012/09/node-js-for-acs-public-developer-preview.htmlAppc Custom code tutorial - http://cloud.appcelerator.com/docs/nodejs/custom_code_tutorial

×