官术网_书友最值得收藏!

Node community – problem solving open source libraries

Now, let's go to the last sentence on the Node website, as shown in the following screenshot:

Node.js' package ecosystem, npm, is the largest ecosystem of open-source libraries in the world. This is what really makes Node fantastic. This is the cherry on top-the community, the people every day developing new libraries that solve common problems in your Node.js applications.

Things such as validating objects, creating servers, and serving up content live using sockets. There's libraries already built for all of those so you don't have to worry about this. This means that you can focus on the specific things related to your application without having to create all this infrastructure before you can even write real code, code that does something specific to your apps use case.

Now, npm, which is available on npmjs.org, is the site we'll be turning to for a lot of third-party modules:

If you're trying to solve a problem in Node that sounds generic, chances are that someone's already solved it. For example, if I want to validate some objects, let's say I want to validate that a name property exists and that there's an ID with a length of three. I could go into Google or go into npm; I usually choose Google, and I could Google search npm validate object.

When I google that, I'll just look for results from npmjs.com, and you can find the first three or so are from that:

I can click the first one, and this will let me explore the documentation and see if it's right for me:

This one looks great, so I can add it to my app without any effort.

Now, we'll go through this process. Don't worry, I'm not going to leave you high and dry on how to add third-party modules. We'll be using a ton of them in the book because this is what real Node developers do. They take advantage of the fantastic community of developers, and that's the last thing that makes Node so great.

This is why Node has come to the position of power that it currently sits at, because it's non-blocking, meaning it's great for I/O applications, and it has a fantastic community of developers. So, if you ever want to get anything done, there's a chance someone already wrote the code to do it.

This is not to say you should never use Rails or Python or any other blocking language again, that is not what I'm getting at. What I'm really trying to show you is the power of Node.js and how you can make your applications even better. Languages like Python have things such as the library Twisted, which aims to add non-blocking features to Python. Though the big problem is all of the third-party libraries, as they are still written in a blocking fashion, so you're really limited as to which libraries you can use.

Since Node was built non-blocking from the ground up, every single library on npmjs.com is non-blocking. So you don't have to worry about finding one that's non blocking versus blocking; you can install a module knowing it was built from the ground up using a non blocking ideology.

In the next couple of sections, you'll be writing your very first app and running it from Terminal.

主站蜘蛛池模板: 乌拉特前旗| 铜梁县| 万州区| 洱源县| 左权县| 会理县| 磐石市| 句容市| 翁源县| 扎兰屯市| 泾源县| 兰溪市| 建平县| 吉林市| 普安县| 图木舒克市| 阿拉善盟| 屏南县| 乐东| 邵阳市| 古丈县| 德钦县| 九龙坡区| 屯留县| 濮阳县| 扎赉特旗| 凤凰县| 海晏县| 定兴县| 莲花县| 庆云县| 惠来县| 荣昌县| 湄潭县| 左云县| 东明县| 河曲县| 龙江县| 日照市| 东方市| 达拉特旗|