Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs: Where or How to write complicated business logic?

Recently I got introduced to node.js and cool packages like express and jade. I have few questions consistently knocking my door:

If I pick node.js to build my next website, I will be using JavaScript to write my server-side complicated logic? but I don't think you can compare JavaScript with Java or Python to write server-side code as they have such a vast ocean of libraries. Is node.js really meant for it? or I have missed something?

Can I call Java or Python from node.js?

like image 225
Vishal Avatar asked Aug 11 '11 22:08

Vishal


People also ask

What is business logic in node JS?

Kinvey Business Logic is a node. js code execution runtime that allows you to customize the behavior of requests to your backend by providing a means to implement server-side business logic.

Where does business logic go in Express?

there is only one place where you can put your business logic is controllers, because models is responsive to deal with DB communication, routers are used to define your route, and services are used for exchanging the information.

Is node JS suitable for heavy computational tasks?

However, web servers that implement computational-heavy or processes-heavy tasks are not a good fit for Node. js. The programming community is still apprehensive of using Node with a relational database given Node tools for relational databases are still not as developed as compared to other languages.

Is NodeJS harder than Java?

js environment offers fast and easy code writing due to its simple syntax and interpreted code. Overall, it is easy to grasp, especially for developers skilled in JavaScript. Java, on the other hand, has a slightly steeper learning curve, as it has a very broad ecosystem.


1 Answers

Not quite sure what most of these folks are talking about.

A "vast ocean of libraries" is something the community is actively working on. Check this: http://search.npmjs.org/#/_analytics -- there were 8 packages published yesterday

Its not going to solve your software design for you. As for where and how to write business logic, many of us embrace mvc or mvvm or something close to it. If you're building an application and like how Rubyists (for example), structure their code you might look at doing something just like that -- aint nobody going to tell you how to structure your code.

Check https://github.com/joyent/node/wiki/modules

Some of the more popular libraries for doing the day to day:

  • Express: http://expressjs.com/ - https://github.com/visionmedia/express
    • Sinatra inspired, use it to build a typical web app
    • Stats: 3407 watchers, 286 forks, on pull request 778
    • Compare that to Sinatra itself! 2529 watchers, 366 forks
    • With connect, it supports all kinds of middleware:
      • sessions,
      • all kinds of routing,
      • static files
      • some 15 different templating engines
      • validation, form handling, etc, etc
  • Socket.io: http://socket.io/ - make it 'real-time'
  • DNode: https://github.com/substack/dnode - do rpc between anything
  • Backbone.js: http://documentcloud.github.com/backbone/ - MVC
    • Variety of techniques for re-using your models on the server:
    • http://andyet.net/blog/2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/
  • Spine.js: http://maccman.github.com/spine.tutorials/index.html - MCV
    • Techniques for re-using code on the server:
    • http://maccman.github.com/spine.tutorials/node.html
  • caolan/async: https://github.com/caolan/async - Help manage your async business logic
  • Database, pick your poision
    • node_redis, https://github.com/mranney/node_redis - or one of the eight other clients
      • "This is a complete Redis client for node.js. It supports all Redis commands"
    • node-mysql, https://github.com/felixge/node-mysql - or one of eleven other clients/orms
    • node-mongodb-native, https://github.com/christkv/node-mongodb-native
    • node-postgres, https://github.com/brianc/node-postgres

There's also a host of ORMs out there, if thats your bag. Things like http://mongoosejs.com/, http://sequelizejs.com/ and friends

Test-driven development is at the core of node. There are 15 different TDD packages to choose from that range from full code coverage analysis to custom assert modules.

Saying all modules are incomplete is silly. There is an incredibly dedicated group of people building and maintaining tons working open-source in this community every day.

There might be reasons to pass over node, but its not for an inactive community or lack of libraries.

like image 149
Josh Avatar answered Oct 05 '22 16:10

Josh