Nodejs: Where or How to write complicated business logic?

前端 未结 6 1487
别那么骄傲
别那么骄傲 2021-01-30 08:55

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 webs

相关标签:
6条回答
  • 2021-01-30 09:21

    There are some things that JavaScript just can't do. If you come up against those Node might not be the best choice for your app. However you can probably accomplish most of what you need.

    As far as the API being limited, I suggest you take a look at npm and all the libraries in its repository. Specifically ones like underscore.js. Many aim to fill in the gaps of what native JavaScript lacks compared to other languages.

    0 讨论(0)
  • 2021-01-30 09:22

    I think you'll be surprised by the amount of work you can get done in JavaScript via Node.js. There are a bunch of libraries available for Node and more are being written all the time. Furthermore, native extensions are also available for those times where you might need to drop down to a lower-level.

    If you think there's a gap where Node won't be able to provide for your business logic, take a look around NPM or give Google a quick serch to see if anyone else has already solved your problem.

    0 讨论(0)
  • 2021-01-30 09:31

    Of course, you can use Python, PHP, c++ or other technologies with nodejs 'cuz node can run it as a child process. Nodejs give you the freedom to use any technology which you want inside itself. You can use whatever you want combining the most performance programs.

    0 讨论(0)
  • 2021-01-30 09:36

    I would say you missed something - more specifically, the core purpose of Node.js, that is, the asynchronous I/O model.

    I started a little pet project to test Node.js - how it "feels" and how to program on it. I became impressed by the ease of working in such ecosystem: Node.js code is easy to write (although its asynchronous paradigm is not that straightforward for the conventional programmer), libraries are easy to build etc. etc. Even npm is amazingly easy: I just found the most straightforward way to provide code of your own as a library is to make a public package of it - and it is absurdly easy!

    However, there is not much good tools to work with Node.js. Maybe because it is too easy to do anything, most libraries are partially-implemented, undocumented solutions.

    Also, note that the relevant difference of Node.js is not the JavaScript language, but the asynchronous I/O model. It is the most interesting aspect of Node.js, but the asynchronous programming style is not as well tested as the conventional way of web development. Maybe it is really the marvel that is propagandized - or perhaps, it is not as good as promised.

    Even in the case it pays off, will you have enough developers to maintain such an (at least still) unusual codebase? If you can get a lot of advantages from the asynchronous "way of life" of Node.js, you can use more consolidated languages and frameworks, such as Twisted for Python (which is my preferred languabe, so take care with my opinion :) ). There may be something like this for Java, too. Anyway, I suspect that you do not have a lot of interest in this model for now, since your question focuses more on languages than in the programming paradigm, so Node.js does not have much to offer to you anyway.

    So... no, I would not develop something professonaly in Node.js for now, although I think it is both fun and instructive to study. You can do it, however - just do not do it without having in mind the main purpose of Node.js: asynchronous-IO, event-driven programming. If it is what you want, Node.js is a good alternative.

    0 讨论(0)
  • 2021-01-30 09:45

    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.

    0 讨论(0)
  • 2021-01-30 09:46

    Ryan did not start with JavaScript. A large part of why Node was created in JavaScript is that JavaScript lacked vast oceans of libraries.

    Those vast oceans of libraries are almost all written in blocking code.

    To take full advantage of Node.js you need to limit your self to non blocking libraries. Which means that might need to write some libraries to complete your project in Node.js.

    0 讨论(0)
提交回复
热议问题