npm quick start for beginner

npm Quick Start Guide for Linux

✅ 1. Install Node.js and npm on Linux

npm comes bundled with Node.js. To install both:

Using package manager (RHEL/CentOS/Fedora)

bash 复制代码
sudo yum install -y nodejs npm

Using package manager (Debian/Ubuntu)

bash 复制代码
sudo apt update
sudo apt install -y nodejs npm

Verify installation

bash 复制代码
node -v
npm -v

Tip: For latest versions, use NodeSource repository:

bash 复制代码
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs

Or for Debian/Ubuntu:

bash 复制代码
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

✅ 2. Initialize a Project

Create a new directory and initialize npm:

bash 复制代码
mkdir my-app && cd my-app
npm init -y

This creates package.json with default settings.


✅ 3. Install Dependencies

Install a runtime dependency:

bash 复制代码
npm install lodash

Install a development dependency:

bash 复制代码
npm install --save-dev eslint

✅ 4. Use Installed Packages

Create index.js:

javascript 复制代码
const _ = require('lodash');
console.log(_.shuffle([1, 2, 3, 4]));

Run the script:

bash 复制代码
node index.js

✅ 5. Manage Dependencies

Update all dependencies:

bash 复制代码
npm update

Remove a dependency:

bash 复制代码
npm uninstall lodash

✅ 6. Run Scripts

Add a script in package.json:

json 复制代码
"scripts": {
  "start": "node index.js"
}

Run it:

bash 复制代码
npm start

✅ 7. Publish Your Package (Optional)

Login to npm:

bash 复制代码
npm login

Publish:

bash 复制代码
npm publish

✅ Common Commands Summary

Command Description
npm init Initialize a project
npm install <pkg> Install a dependency
npm install -g <pkg> Install globally
npm uninstall <pkg> Remove a dependency
npm update Update dependencies
npm run <script> Run a script

✅ Summary

npm is the default package manager for Node.js, enabling easy dependency management, automation via scripts, and access to the largest JavaScript package ecosystem.

相关推荐
计算机魔术师16 分钟前
Fable 5.1 来了,智能体任务成本降 45%——Anthropic 这次为何降价这么狠
前端
Csvn17 分钟前
现代 CSS 新特性深度:container query、:has()、@scope 与 subgrid
前端
计算机魔术师22 分钟前
Anthropic 自己承认:模型越来越难管住了
前端
两只羊ovo30 分钟前
Agent 干活的底层地基:path 路径 + fs 文件系统,一次讲透
前端
一用书生31 分钟前
我给 ChatGPT、DeepSeek、Kimi 都加了一个「保存为笔记」按钮
前端·ai编程·vibecoding
咖啡无伴侣33 分钟前
1. 从零搭建企业级 Monorepo 工程化模板:初始化、应用创建与共享 TypeScript 配置
前端·前端框架
moonsims34 分钟前
再议AiBrainBox-V的前左右三目布局-满足多目SLAM算法;对比单下视VIO(低空、地面纹理丰富、飞行速度适中无人机 )&多目VIO
前端·人工智能·量子计算
AI编程实验室35 分钟前
Agent Handoff 自动跟踪 Skill:安装、事件映射与证据分级
前端·ai编程
KoPa36 分钟前
HeySmart:事件总线——异步解耦的艺术
前端·后端
金花顺36 分钟前
ndroid 音频系统:AudioTrack 源码深度解析(从 Java 构造到 Native 启动)
前端·架构