博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Node JS简介– Node.js基础
阅读量:2535 次
发布时间:2019-05-11

本文共 15405 字,大约阅读时间需要 51 分钟。

We are going to deliver a sequence of posts on “How to develop Applications using Node JS, Express JS, Angular JS, Mongo DB, Redis, and RESTful WebServices“.

我们将在“ 如何使用Node JS,Express JS,Angular JS,Mongo DB,Redis和RESTful WebServices开发应用程序 ”上发表一系列帖子。

We will discuss all these posts on Windows Environment only. There is no much difference in Node JS Platform installation and developing applications in other OS Environments.

我们将仅在Windows Environment上讨论所有这些文章。 在其他操作系统环境中,Node JS平台的安装和开发应用程序没有太大区别。

In this post, we are going to discuss about some basics of Node JS Platform.

在本文中,我们将讨论Node JS Platform的一些基础知识。

什么是Node JS? (What is Node JS?)

Node JS is an Open Source Java Script Platform used to develop fast and scalable server-side and networking applications very easily.

Node JS是一个开源Java脚本平台,用于非常轻松地开发快速且可扩展的服务器端和网络应用程序。

Google’s V8 Engine is an Open Source JavaScript Engine for the Chrome Web browser. V8 Engine is completely written in C++ Language.

Google的V8引擎是用于Chrome Web浏览器的开源JavaScript引擎。 V8 Engine完全用C ++语言编写。

Ryan Dahl is a big fan of “Google’s Gmail”. He was impressed by Gmail performance and started created new Platform.

Ryan Dahl是“ Google的Gmail”的忠实拥护者。 Gmail的性能给他留下了深刻的印象,并开始创建新的平台。

Ryan Dahl has developed a Server-Side Platform “Node JS” in 2009 on top of Google’s V8 Engine. That means Node JS applications run on V8 Engine.

Ryan Dahl在2009年基于Google的V8引擎开发了服务器端平台“ Node JS”。 这意味着Node JS应用程序可以在V8 Engine上运行。

Unlike some UI Frameworks for example Angular JS, use to write Client-side JavaScript, Node JS Platform is used to write Server-side JavaScript.

与用于编写客户端JavaScript的某些UI框架(例如Angular JS)不同,Node JS Platform用于编写服务器端JavaScript。

We can run Node JS applications on most of the OS Platforms like Windows, Linux, Mac etc.

我们可以在Windows,Linux,Mac等大多数OS平台上运行Node JS应用程序。

Official Website for Node JS Platform:

Node JS平台的官方网站: :

什么不是Node JS? (What is NOT Node JS?)

Node JS is a Platform. It is not a Framework or Web Framework. It is not a Language.

Node JS是一个平台。 它不是框架或Web框架。 它不是语言。

It is a Platform which contains thousands of thousands of modules to develop wide variety of applications. We can install base Node JS Platform and update all your application required modules very easily.

它是一个包含成千上万个模块的平台,用于开发各种应用程序。 我们可以安装基本的Node JS平台并非常轻松地更新您所有应用程序所需的模块。

Node JS “Module” is also known as Package. Now onwards, when we refer Module means Node JS Package.

节点JS“模块”也称为包。 现在开始,当我们提到Module时就是Node JS Package。

Node JS is not for Multi-Threaded applications. It follows Single Thread with Event Loop architecture. If you don’t know what is “Even Loop” architecture, don’t get tense at this moment. We will discuss on “What is Event Loop and How Node JS deals with multiple requests” in coming posts.

Node JS不适用于多线程应用程序。 它遵循具有事件循环体系结构的单线程。 如果您不知道什么是“ Even Loop”架构,那么现在不要紧张。 我们将在以后的文章中讨论“什么是事件循环以及Node JS如何处理多个请求”。

We will discuss how to setup Node JS Base Platform and how to add/install required modules at required time in coming posts.

我们将在后续文章中讨论如何设置Node JS Base Platform以及如何在需要的时间添加/安装所需的模块。

Node JS的功能 (Features of Node JS)

  • Modularity

    Major advantage of Node JS Platform is that it’s modularity. Each and every functionality is divided and implemented as a separate module or package. When we install Node JS Platform, by default it installs only few modules. If our application requires other modules, then we can easily install and configure then at any point of our application development phases.

    Node JS has thousands of thousands modules. Some modules were developed by Node JS Community and some were by Third-party Clients. We will discuss and provide some examples about these modules in coming posts.

    While writing this post, Node JS Platform supports the following number of packages.

    We can check this updates on its official website:

    Some of the Node JS Modules are written in Java Script and some are in C/C++ Language. It’s 40% modules are written in JS and 60% modules are written C/C++.

    模块化

    Node JS平台的主要优点是它的模块化。 每个功能都被划分并实现为单独的模块或包。 当我们安装Node JS Platform时,默认情况下它仅安装几个模块。 如果我们的应用程序需要其他模块,那么我们可以在应用程序开发阶段的任何时候轻松地安装和配置。

    Node JS有成千上万个模块。 一些模块是由Node JS社区开发的,而某些则是由第三方客户端开发的。 我们将在以后的文章中讨论并提供有关这些模块的一些示例。

    在撰写本文时,Node JS Platform支持以下数量的软件包。

    我们可以在其官方网站上查看此更新: :

    一些Node JS模块是用Java脚本编写的,而另一些则是用C / C ++语言编写的。 它的40%模块是用JS编写的,而60%模块是用C / C ++编写的。

  • Express JS

    Node JS is used to develop Server-side Java Script. It also contains a separate module for Web Application Framework i.e. Express JS.

    Express JS

    Node JS用于开发服务器端Java脚本。 它还包含Web应用程序框架的单独模块,即Express JS。

  • Non-blocking or Asynchronous IO

    Node JS supports Non-blocking IO i.e. it uses Asynchronous IO Model to interact with File system or to do Socket communication or network communication.

    Asynchronous IO Model means if IO processing is taking more time, then it permits other processing to continue before the transmission has finished.

    Java Developers are very much familiar about Blocking IO and Non-Blocking IO. Java IO package follows Blocking IO or Synchronous IO Architecture whereas Java NIO 2 follows Non-Blocking IO or Asynchronous IO Architecture.

    非阻塞或异步IO

    Node JS支持非阻塞IO,即它使用异步IO模型与文件系统交互或进行Socket通信或网络通信。

    异步IO模型意味着,如果IO处理花费更多时间,则它允许其他处理在传输完成之前继续进行。

    Java开发人员对阻塞IO和非阻塞IO非常熟悉。 Java IO软件包遵循Blocking IO或Synchronous IO Architecture,而Java NIO 2遵循Non-Blocking IO或Asynchronous IO Architecture。

  • Event-Driven Asynchronous Platform
    Node JS Platform follows Even-Driven Loop architecture to interact or handle requests. We will discuss in details about “Even-Drive Loop” in coming posts.

    事件驱动的异步平台
    Node JS平台遵循均匀驱动循环体系结构来交互或处理请求。 我们将在以后的文章中详细讨论“ Even-Drive Loop”。
  • MongoDB Wrappers API
    Node JS platform contains a separate module to integrate MongoDB No SQL database with applications. It provides a MongoDB wrapper API.

    We can use this API to write JavaScript easily to interact with MongoDB database. Node JS-mongodb module uses Mongoose to interact with MongoDB database.

    MongoDB Wrappers API
    Node JS平台包含一个单独的模块,用于将MongoDB No SQL数据库与应用程序集成。 它提供了MongoDB包装器API。

    我们可以使用此API轻松编写JavaScript以与MongoDB数据库进行交互。 节点JS-mongodb模块使用Mongoose与MongoDB数据库进行交互。

  • Redis Client Library API

    Node JS platform contains a separate module to integrate Redis No SQL database with applications. It provides a Redis wrapper API. We can use this API to write JavaScript easily to interact with Redis database.

    Redis客户端库API

    Node JS平台包含一个单独的模块,用于将Redis No SQL数据库与应用程序集成。 它提供了Redis包装器API。 我们可以使用此API轻松编写JavaScript以与Redis数据库进行交互。

  • Jade Template Engine

    Node JS platform supports many template engines to write HTML. Default template engine supported by Node JS is “Jade”.

    Jade is a whitespace-sensitive template engine for developing HTML applications very easily.

    We can write template pages once and reuse them very easily to reduce development time. We will discuss how to install and write Jade templates in a separate post.

    玉模板引擎

    Node JS平台支持许多模板引擎来编写HTML。 Node JS支持的默认模板引擎是“ Jade”。

    Jade是一个对空格敏感的模板引擎,可非常轻松地开发HTML应用程序。

    我们可以编写一次模板页面,然后非常轻松地重用它们,以减少开发时间。 我们将在另一篇文章中讨论如何安装和编写Jade模板。

  • Web Server

    We can develop and use HTTP Web Server within no time. We need to use http package to implement Web Server. We will discuss one post on how to install http package and develop a Web Server.

    网络服务器

    我们可以立即开发和使用HTTP Web Server。 我们需要使用http包来实现Web服务器。 我们将讨论一篇有关如何安装http软件包和开发Web服务器的文章。

  • Better Socket API

    Node JS Platform provides very good Socket Module API to develop Real-time, Multi-User Chat and Multi-Player Gaming Applications very easily. It supports Unix Socket programming like pipe().

    更好的套接字API

    Node JS平台提供了非常好的套接字模块API,可以非常轻松地开发实时,多用户聊天和多玩家游戏应用程序。 它支持Unix套接字编程,例如pipe()。

Node JS的优点 (Advantages of Node JS)

  • One Language and One Data Format
    We need to use one and only one language to write whole applications i.e. Java Script. We need to code all layers from UI to Controller to Business Layer to Persistence Layer (From Front-End to Back-End) in Java Script only.

    All layers from Front-End to Back-End support same Data Format i.e. JSON (Java Script Object Notation). UI Layer Angular JS Supports JSON Format, Server-Side Scripts written in Express JS supports JSON Format and Back-end MongoDB NO SQL supports same JSON Format.

    一种语言和一种数据格式
    我们只需要使用一种语言来编写整个应用程序,即Java Script。 我们只需要用Java脚本对从UI到控制器到业务层再到持久层(从前端到后端)的所有层进行编码。

    从前端到后端的所有层都支持相同的数据格式,即JSON(Java脚本对象表示法)。 UI层Angular JS支持JSON格式,用Express JS编写的服务器端脚本支持JSON格式,后端MongoDB NO SQL支持相同的JSON格式。

  • Open Source

    Node JS is Open Source Module. It provides many modules for free to use in our applications.

    开源的

    节点JS是开源模块。 它提供了许多可在我们的应用程序中免费使用的模块。

  • Highly Scalable

    To improve our application performance, we will scale our infrastructure. There are two ways to scale any application:

    1. Horizontal Scaling
    2. Vertical Scaling

    Vertical Scalability means adding more resources to a single node. Horizontal Scalability means adding more nodes to a system.

    Node JS uses Horizontal Scaling instead of Vertical Scaling to our applications. It’s consistent with today’s Cloud Technology trend.

    高度可扩展

    为了提高我们的应用程序性能,我们将扩展基础架构。 有两种扩展任何应用程序的方式:

    1. 水平缩放
    2. 垂直缩放

    垂直可伸缩性意味着向单个节点添加更多资源。 水平可伸缩性意味着向系统添加更多节点。

    Node JS对我们的应用程序使用“水平缩放”而不是“垂直缩放”。 这与当今的云技术趋势保持一致。

  • Better Performance and Low Latency

    I/O operations often blocks our application because it can take a long time to read a big file, or make a large query against a database, or wait for any stream of data to fully transmit.

    As Node JS follows Non-Blocking IO architecture and also uses only JavaScript to develop entire application, we can achieve better performance and low latency.

    If we develop our UI and Data Intensive applications by using MEAN Stack, we can achieve very high performance. MEAN Stands for MongoDB, Express JS, Angular JS and Node JS.

    更好的性能和较低的延迟

    I / O操作通常会阻塞我们的应用程序,因为它可能需要很长时间才能读取大文件,或者对数据库进行大查询,或者等待任何数据流完全传输。

    由于Node JS遵循无阻塞IO架构,并且仅使用JavaScript开发整个应用程序,因此我们可以获得更好的性能和较低的延迟。

    如果我们使用MEAN Stack开发UI和数据密集型应用程序,则可以实现很高的性能。 MEAN代表MongoDB,Express JS,Angular JS和Node JS

  • Caching Modules

    Node JS Modules are cached once they are loaded into application for first time. Multiple calls to load a module may not cause the module code to be executed multiple times.

    缓存模块

    节点JS模块在首次加载到应用程序后即被缓存。 多次调用以加载模块可能不会导致模块代码多次执行。

  • Less Problems with Concurrency
    Node JS does not follow Multi-Thread architecture. It follows Single-Thread with Event Loop Architecture. It serves any number of requests without any issues.
    Node JS does NOT need to handle pooling of requests to a set of threads. That’s why it has less overhead to handle multiple requests concurrently.

    并发问题更少
    Node JS不遵循多线程体系结构。 它遵循具有事件循环体系结构的单线程。 它可以处理任何数量的请求,而不会出现任何问题。
    Node JS不需要处理对一组线程的请求池。 这就是为什么同时处理多个请求的开销较小的原因。
  • Easy to Extend and Lightweight
    We can install only required modules and use them to develop applications. Whenever we need to add new feature or module, we can easily extend it.
    By following this approach, we can also achieve very light-weight nature into our applications.

    易于扩展且轻巧
    我们只能安装所需的模块,并使用它们来开发应用程序。 每当我们需要添加新功能或模块时,我们都可以轻松对其进行扩展。
    通过遵循这种方法,我们还可以在应用程序中实现非常轻量的特性。
  • Faster Development and Easy to Maintain
    As Node JS Platform had already provided support for many modules, we can use them and develop wide variety of applications within no time. We can develop and maintain Node JS applications very easily.

    更快的开发和易于维护
    由于Node JS平台已经提供了对许多模块的支持,因此我们可以立即使用它们并开发各种应用程序。 我们可以非常轻松地开发和维护Node JS应用程序。
  • REST API
    Node JS Platform supports developing RESTful Web Services API very easily.

    REST API
    Node JS Platform支持非常轻松地开发RESTful Web服务API。
  • Many Development Frameworks and Tools
    We can get many development tools like IDE and UI Frameworks to develop Node JS applications very easily.

    许多开发框架和工具
    我们可以获得很多开发工具,例如IDE和UI框架,可以非常轻松地开发Node JS应用程序。
  • Active Development Community
    Node JS Development Community is very active in adding new modules or packages to existing modules to support wide variety of applications development.

    积极发展社区
    Node JS开发社区非常积极地向现有模块添加新模块或程序包,以支持各种应用程序开发。
  • Unit Testing
    In Node JS applications, we need to write whole code in Java Script. Today we have many Java Script Unit Testing frameworks and tools like Jasmin Framework.

    单元测试
    在Node JS应用程序中,我们需要用Java Script编写整个代码。 今天,我们拥有许多Java脚本单元测试框架和工具,例如Jasmin Framework。
  • Streaming Data
    We can easily develop Streaming-based data applications by using Node JS.

    流数据
    我们可以使用Node JS轻松开发基于流的数据应用程序。
  • Creating Servers
    Node JS Platform has some built-in API to develop or create HTTP Server, DNS Server, TCP Server etc very easily or quickly.

    创建服务器
    Node JS平台具有一些内置的API,可以非常容易或快速地开发或创建HTTP Server,DNS Server,TCP Server等。
  • It can handle thousands of concurrent connections with minimal overhead (CPU/Memory) on a single process

    它可以在单个进程上以最少的开销(CPU /内存)处理数千个并发连接
  • Easy Module Loading process
    It is very easy to load required Node JS Modules into Node JS Applications. We just need to use require() statement in our application. It is similar to “import” statement in Java Programming language. We will discuss about require() in detail with some examples in coming posts.

    简单的模块加载过程
    将所需的Node JS模块加载到Node JS应用程序中非常容易。 我们只需要在我们的应用程序中使用require()语句。 它类似于Java编程语言中的“ import”语句。 我们将在后续文章中详细讨论有关require()的示例。

Node JS的局限性 (Limitations of Node JS)

  • It does NOT support Multi-threading programming.

    它不支持多线程编程。
  • It does support for Computational Intensive Tasks. Node JS struggles in handling of very high computational intensive tasks, because whenever it does something long running task, it will queue all remaining incoming requests, because it follows Single-Thread Architecture with Event Loop.

    它确实支持计算密集型任务。 Node JS难以处理大量计算密集型任务,因为每当它执行长时间运行的任务时,由于它将遵循带有事件循环的单线程体系结构,因此它将对所有剩余的传入请求进行排队。
  • Don’t use Node JS for Blocking/Synchronous and CPU-intensive tasks.

    不要将Node JS用于阻止/同步和占用大量CPU的任务。
  • Unstable API – Node JS is still in Beta stage and most of its modules are in unstable state. It’s not ready for Production or Live Systems.

    API不稳定-Node JS仍处于Beta阶段,并且其大多数模块处于不稳定状态。 还没有准备好用于生产或实时系统。
  • 谁使用Node JS平台 (Who uses Node JS Platform)

    Now-a-Days many people are using Node JS Platform to develop and maintain their applications. Some of the popular companies who are using Node JS Platform are;

    如今,许多人正在使用Node JS平台来开发和维护他们的应用程序。 一些正在使用Node JS Platform的受欢迎的公司包括:

    • DOW JONES

      道琼斯
    • When-To-Manage

      何时管理
    • Linkedin

      领英
    • MicroSoft

      微软
    • Twelephone (It is a service for making calls right from Twitter account)

      Twelephone(这是一种从Twitter帐户直接拨打电话的服务)
    • Yahoo

      雅虎
    • PayPal

      贝宝
    • eBay

      易趣
    • STRONGLoop

      斯特龙·古普
    • Wallmart

      沃尔玛
    • Groupon

      Groupon
    • SAP

      树液
    • PINT Web Platform (PWP)

      PINT网络平台(PWP)
    • Cloud9 IDE

      Cloud9 IDE
    • Dropbox

      投寄箱
    • ZingChart

      金图
    • Chess (It is an online game available on facebook.com)

      国际象棋(这是一个在线游戏,可在facebook.com上使用)

    Node JS应用程序 (Node JS Applications)

    We can use Node JS Platform to develop the following kind of applications.

    我们可以使用Node JS Platform开发以下类型的应用程序。

    • Network applications

      网络应用
    • Asynchronous Events

      异步事件
    • Intelligent Networking Proxies

      智能网络代理
    • Proxy Server

      代理服务器
    • Multiplayer Game Applications

      多人游戏应用
    • Data Intensive Real-time applications

      数据密集型实时应用
    • Web Applications

      网络应用
    • High Definition(HD) Voice and Video Communications

      高清(HD)语音和视频通信
    • File Uploading Tools

      文件上传工具
    • Process Monitoring Tools

      流程监控工具
    • Many-To-Many Instant Chatting Applications

      多对多即时聊天应用程序
    • Many-To-Many Instant Messing Applications

      多对多即时处理应用程序
    • HTTP Web Server

      HTTP Web服务器
    • Real-time Logistics Systems

      实时物流系统
    • Streaming Server

      流媒体服务器
    • High Concurrency Applications

      高并发应用
    • Communication Hubs

      通讯中心
    • Coordinators

      协调员
    • DNS Server

      DNS服务器
    • Static File Server

      静态文件服务器
    • TCP Server

      TCP服务器
    • Stock-Trading Dashboard

      股票交易仪表板

    In coming post, we will discuss about “How to setup Node JS Base Platform” and also about “Node JS Components“.

    在接下来的文章中,我们将讨论“ 如何设置Node JS基本平台 ”以及“ Node JS组件 ”。

    翻译自:

转载地址:http://hvqzd.baihongyu.com/

你可能感兴趣的文章
BiTree
查看>>
5个基于HTML5的加载动画推荐
查看>>
水平权限漏洞的修复方案
查看>>
静态链接与动态链接的区别
查看>>
Android 关于悬浮窗权限的问题
查看>>
如何使用mysql
查看>>
linux下wc命令详解
查看>>
敏捷开发中软件测试团队的职责和产出是什么?
查看>>
在mvc3中使用ffmpeg对上传视频进行截图和转换格式
查看>>
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>
ajax跨域,携带cookie
查看>>
阶段3 2.Spring_01.Spring框架简介_03.spring概述
查看>>
阶段3 2.Spring_02.程序间耦合_1 编写jdbc的工程代码用于分析程序的耦合
查看>>
阶段3 2.Spring_01.Spring框架简介_04.spring发展历程
查看>>
阶段3 2.Spring_02.程序间耦合_3 程序的耦合和解耦的思路分析1
查看>>
阶段3 2.Spring_02.程序间耦合_5 编写工厂类和配置文件
查看>>
阶段3 2.Spring_01.Spring框架简介_05.spring的优势
查看>>