node.js npm安装_Node.js组件– Node.js模块,NPM安装更新卸载示例

本文介绍了Node.js的主要组件,包括Node CLI、NPM及其作用。NPM作为Node.js的包管理器,用于方便地安装、更新和卸载模块。文章还提到了`package.json`文件在管理应用依赖中的重要性,并强调了Node.js模块化的特点,以及如何通过NPM安装和管理核心模块与第三方模块。
摘要由CSDN通过智能技术生成

node.js npm安装

In my previous post, we have discussed about “How to setup Node JS Base Environment“. In this post, we will discuss about “Node JS Platform Major Components” and NPM install update uninstall example.

在我以前的文章中,我们讨论了“ 如何设置Node JS基本环境 ”。 在本文中,我们将讨论“ Node JS Platform主要组件 ”和NPM安装更新卸载示例。

Node JS平台组件 (Node JS Platform Components)

Node JS is Platform, not a Framework. It contains many components to develop, test and deploy Enterprise applications.

节点JS是平台,而不是框架。 它包含许多用于开发,测试和部署企业应用程序的组件。

Node JS Components List:

节点JS组件列表:

节点CLI (Node CLI)

Node JS Platform has a CLI (Command Line Interface) to run basic commands and also script files.

Node JS平台具有一个CLI(命令行界面),用于运行基本命令以及脚本文件。

When we install Node JS Platform, by default we will get this component. We do not need to any extra configurations for this component.

当我们安装Node JS Platform时,默认情况下将获得此组件。 我们不需要为此组件进行任何其他配置。

We can observe “node.exe” file at NODSJS_HOME. It is also known as Node Platform CLI component.

我们可以在NODSJS_HOME上观察“ node.exe ”文件。 它也被称为Node Platform CLI组件。

How to access Node CLI:

如何访问Node CLI

  1. Open Command prompt at NODSJS_HOME
    Node.js-CLI-1

    在NODSJS_HOME上打开命令提示符
  2. Run “node.exe” command

    Now we are able to see NODE CLI i.e. “>”, that means our Node JS Setup is working fine.

    Here we can run basic Java Script commands one by one or entire Java Script files (*.js files) to test the basic functionality.

    node.exe ”命令

    现在我们可以看到NODE CLI,即“>”,这意味着我们的Node JS安装程序可以正常工作。

    在这里,我们可以逐个运行基本Java Script命令或运行整个Java Script文件(* .js文件)以测试基本功能。

NPM (NPM)

NPM stands for Node Package Manager. NPM is used to install, update, uninstall and configure Node JS Platform modules/packages very easily.

NPM代表节点软件包管理器。 NPM用于非常轻松地安装,更新,卸载和配置Node JS Platform模块/软件包。

When we install Node JS Base Platform, it installs only few components, modules and libraries like Node CLI, NPM etc. From this point, we can use NPM to upgrade Node JS Platform with our required modules.

当我们安装Node JS Base Platform时,它仅安装了很少的组件,模块和库,例如Node CLI,NPM等。从这一点来看,我们可以使用NPM来用所需的模块升级Node JS Platform。

By default Node JS platform install NPM module. We can observe this at NODEJS_HOME\node_modules folder as shown below.

默认情况下,Node JS平台安装NPM模块。 我们可以在NODEJS_HOME \ node_modules文件夹中观察到此情况,如下所示。

When we install any other required modules, we can observe new folders here. That means for each module or package, Node JS maintains a separate folder here.

当我们安装任何其他必需的模块时,我们可以在此处观察新文件夹。 这意味着对于每个模块或软件包,Node JS都会在此处维护一个单独的文件夹。

We can observe “npm.cmd” in Windows environment at NODEJS_HOME. This command is used to run NPM component from command prompt.

Node.js-NPM-cmd

我们可以在Windows环境中的NODEJS_HOME上观察“ npm.cmd ”。 此命令用于从命令提示符运行NPM组件。

NOTE: In simple words, Maven is used to build Java modules into jar files and NPM is used to create, install, install and update Node Modules.

注意 :简单来说,Maven用于将Java模块构建到jar文件中,而NPM用于创建,安装,安装和更新Node Modules。

To check npm version, run “npm -v command as shown in below image.

要检查npm版本,请运行“ npm -v命令,如下图所示。

NPM命令语法 (NPM Command Syntax)

  • NPM Install to install a module

    For example, npm install –g express command is used to install Express Module.

    .tg {border-collapse:collapse;border-spacing:0;border-color:#ccc;}
    .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#fff;}
    .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#f0f0f0;}
    .tg .tg-4eph{background-color:#f9f9f9}

    Sl No.Command PartsDescription
    1.-gIt tells install this module globally that is with all administrator permissions.
    2.expressExpress module or package unique name

    We will discuss in-detail about each module installation in coming posts.

    When we install modules by using npm, it use two modes install at two difference locations.

    Local Mode: When we install Node JS Platform, by default it uses Local Mode to install npm module in node_modules directory as shown in below screen shot.

    Sample command for installing express module would be “npm install express“.

    Global Mode: When we use npm command with –g option, it uses Global Mode to install modules as shown in below screen shot for “npm install –g express” command.

    Here “express” module is installed with Global Mode.

    NPM安装以安装模块

    例如, npm install –g express命令用于安装Express Module

    .tg {border-collapse:collapse; border-spacing:0; border-color:#ccc;}
    .tg td {font-family:Arial,sans-serif; font-size:14px; padding:10px 5px; border-style:solid; border-width:1px; overflow:hidden; word-break:normal; border-color :#ccc; color:#333; background-color:#fff;}
    .tg th {font-family:Arial,sans-serif; font-size:14px; font-weight:normal; padding:10px 5px; border-style:solid; border-width:1px; overflow:hidden; word-break :normal; border-color:#ccc; color:#333; background-color:#f0f0f0;}
    .tg .tg-4eph {background-color:#f9f9f9}

    Sl号 命令部分 描述
    1。 -G 它告诉全局安装具有所有管理员权限的该模块。
    2。 表达 Express模块​​或软件包的唯一名称

    我们将在以后的文章中详细讨论每个模块的安装。

    当我们使用npm安装模块时,它使用两种模式在两个不同的位置安装。

    本地模式 :当我们安装Node JS Platform时,默认情况下它使用本地模式在node_modules目录中安装npm模块,如下面的屏幕快照所示。

    用于安装Express模块​​的示例命令为“ npm install express ”。

    全局模式 :当我们将npm命令与–g选项一起使用时,它将使用“全局模式”来安装模块,如下图“ npm install –g express ”命令的屏幕截图所示。

    此处,“ express”模块与全局模式一起安装。

  • NPM uninstall to uninstall or remove an existing module;NPM卸载以卸载或删除现有模块;
  • NPM update to update an existing module;NPM更新以更新现有模块;

package.json (package.json)

package.json” is plain text file in JSON format. It is used to manage our application required module dependencies. We should place this file in our application root folder.

package.json ”是JSON格式的纯文本文件。 它用于管理我们的应用程序所需的模块依赖性。 我们应该将此文件放在应用程序的根文件夹中。

It defines information like our application name, module dependencies, module versions etc. This configurations file is very important and requires more time to explain in detail. We will discuss it in detail with some examples in coming posts.

它定义了诸如我们的应用程序名称,模块依赖项,模块版本等信息。此配置文件非常重要,需要更多时间进行详细说明。 我们将在以后的文章中用一些示例详细讨论它。

Sample package.json file;

示例package.json文件;

{
  "name" : "sampleapp",
  "version" : "1.0.0",
  "dependencies" : {
  }
}

节点模块 (Node Modules)

Node JS is more modular platform. Each functionality is implemented by a separate module or package. It has some core modules like npm, install, uninstall, update etc and rest all modules are third-party modules.

Node JS是一个更加模块化的平台。 每个功能都由单独的模块或程序包实现。 它具有一些核心模块,例如npm,安装,卸载,更新等,其余所有模块都是第三方模块。

When we install Node JS Platform, by default only one module is installed i.e. npm module. We need to use “npm” command to install required modules one by one.

当我们安装Node JS Platform时,默认情况下仅安装一个模块,即npm模块。 我们需要使用“ npm”命令一个接一个地安装所需的模块。

All Core or Default modules are installed at /lib folder as *.js files as show below. In our case this path refers to “D:\NodeJS.V.0.12.0\node_modules\npm\lib”.

所有Core或Default模块都作为* .js文件安装在/ lib文件夹中,如下所示。 在我们的示例中,此路径引用“ D:\ NodeJS.V.0.12.0 \ node_modules \ npm \ lib”。

Node JS has thousands of modules, but here we are going to provide some of the popular modules. We will discuss and provide some examples about these modules in coming posts.

Node JS有成千上万个模块,但是在这里我们将提供一些流行的模块。 我们将在以后的文章中讨论并提供有关这些模块的一些示例。

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

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

A full list of Node JS Platform’s packages or modules can be found on the NPM website https://npmjs.org/.

可以在NPM网站https://npmjs.org/上找到Node JS Platform软件包或模块的完整列表。

Some of the Node JS Modules are written in Java Script and some are in C/C++ Language.

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

开发工具和框架 (Development Tools and Frameworks)

As Node JS Platform became very popular to develop Data-Sensitive Real-time and Network applications, many companies have developed some tools and framework to ease and reduce the overhead of Node JS applications.

随着Node JS平台在开发数据敏感的实时和网络应用程序中变得非常流行,许多公司已经开发了一些工具和框架来减轻和减少Node JS应用程序的开销。

CategoryFramework/Tools
IDEEclipse with node.js plugins, Jetbrains Webstorm, Cloud9 IDE,
Visual Studio Node JS Toolkit
DatabaseMongoose for MongoDB
UI Build ToolsGrunt, Yeoman, Gulp
CLINode CLI, grunt-cli
AuthenticationPassport.js
UI Library ManagementBower
UI FrameworksBackbone.js, Angular.js, Ember.js
Layout FrameworksTwitter Bootstrap Framework
Template EngineJade, EJS, Hogan.JS
CSS EngineStylus, LESS, Compass
Unit Testing FrameworksJasmin, Node Unit
类别 框架/工具
集成开发环境 带有node.js插件的Eclipse,Jetbrains Webstorm,Cloud9 IDE,
Visual Studio节点JS工具包
数据库 MongoDB for Mongoose
UI生成工具 咕unt声,约曼,Gulp
命令行界面 节点CLI,grunt-cli
认证方式 Passport.js
UI库管理 凉亭
UI框架 Backbone.js,Angular.js,Ember.js
布局框架 Twitter Bootstrap框架
模板引擎 Jade,EJS,Hogan.JS
CSS引擎 触控笔,LESS,指南针
单元测试框架 Jasmin,节点单元

We will try to use some of these frameworks and tools to develop our Node JS examples in coming posts.

在接下来的文章中,我们将尝试使用其中一些框架和工具来开发我们的Node JS示例。

翻译自: https://www.journaldev.com/7423/node-js-components-modules-npm-install-update-uninstall-example

node.js npm安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值