npm最基本安装

本文详细介绍了如何在Node.js环境中初始化项目,包括使用npm init创建package.json文件的过程,以及通过npm install安装Gulp及其不同安装方式的区别。此外,还讲解了如何将项目上传至npm仓库和下载项目的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

初始化安装

安装gulp

连接到gulp

上传项目到gulp

下载项目


初始化安装


在自己新建的文件夹内用cmd运行
npm init 

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (demo1)
version: (1.0.0)
description: 新建测试版本
entry point: (index.js)
test command:
git repository:
keywords:
author: cjj
license: (ISC) MIT
About to write to D:\node\initNode\demo1\package.json:

{
  "name": "demo1",
  "version": "1.0.0",
  "description": "新建测试版本",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "cjj",
  "license": "MIT"
}


Is this ok? (yes)

这样就创建完成了(新建完后会自动有一个package.json)

安装gulp

npm install gulp  //只是纯粹的安装gulp
npm install gulp --sava //安装gulp并添加依赖(package.json配置)
npm install gulp --save-dev //安装gulp添加依赖,若别人下载本项目,gulp不会被一起下载
npm install gulp gulp -cli -g //全局安装gulp,并安装gulp手脚架(允许直接使用gulp指令)

连接到gulp


gulp可以上传项目到网站上保存(www.npmjs.com)也跟github一样需要注册
需要你输入用户名和密码以及注册邮箱,登陆成功后可以用
这句指令先登陆连接到服务器

npm adduser


上传项目到gulp

npm publish

这指令(需要在项目文件夹下)即可上传到服务器,需要注意的,其会根据package.json内的name(key名)来作为项目名,而且服务器内的项目名有唯一性,如果gulp服务器已存在同名的项目,那么是不会允许你上传的,需要你更改名字后才允许上传

下载项目

npm install 项目名


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值