当前位置: 首页 > article >正文

How to install Node.js and NPM on CentOS

How to install Node.js and NPM on CentOS

Download Node.js

菜鸟教程-Node.js 安装配置

Introduction

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world. In this article we will explain the steps of installing node.js and npm in CentOS.

Step 1: Add node.js yum repository

First we need to add yum repository of node.js to our system which is sourced from nodejs’ official website. Run the following commands in succession to add the yum repository.

yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
Copy code

# 如果报错如下:

Error: Failed to download metadata for repo 'nodesource': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

# 尝试执行如下命令解决

sudo rm -r /var/cache/dnf

依然不行,去官网查看新版本的重新尝试。

Welcome to Node.js RPM repository

Step 2: Install node.js and NPM

Now it’s time to install the node.js package and NPM package. Run the following command to do so. This single command will install node.js, npm and also other dependent packages.

yum install nodejs
Copy code

Step 3: Verify versions

Having installed the packages, you need to check their versions.

For checking node.js version:

node -v

#output
v6.9.4
Copy code

For checking npm version:

npm -v

#output
3.10.10
Copy code

Step 4: Testing the installation

You can test your installation by creating a test file, say test_server.js

vim test_server.js
Copy code

Then add the following content in the file.

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Welcome');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');
Copy code

Now start the web server using the below command

node --debug test_server.js

debugger listening on port 5858
Server running at http://127.0.0.1:3001/
Copy code

Web server has started which can be accessed using URL http://127.0.0.1:3001/ in your browser.


http://www.kler.cn/news/366487.html

相关文章:

  • windows下pycharm社区版2024下载与安装(包含新建第一个工程)
  • qt QMediaPlaylist
  • 中间件之Seata
  • O2OA如何实现文件跨服务器的备份
  • 前端项目接入sqlite轻量级数据库sql.js指南
  • Scala 提取器(Extractor)
  • 运输层知识点汇总3
  • 【ArcGIS Pro实操第5期】全局及局部空间插值:GPI、LPI、IDW等
  • win7现在还能用吗_哪些配置的电脑还可以安装win7系统
  • 基于JSP实习管理系统【附源码】
  • 五,Linux基础环境搭建(CentOS7)- 安装Kafka
  • 【排序】4.插入排序(含优化)
  • TPLCM柔性屏自动化贴合应用
  • 算法打卡 Day43(动态规划)-背包问题 + 分割等和子集
  • 查看Chrome安装路
  • IDEA项目代码报红,但可以正常编译运行
  • #HarmonyOS:页面和自定义组件生命周期
  • 一站式AI自动化剪辑 内置多种功能 永久免费
  • UI自动化测试实战
  • 使用docker build自制flink镜像供k8s使用
  • 7. 配置
  • 用更多的钱买电脑而不是手机
  • 【pytest学习】pytest.main()
  • 数据库的CURD【MySql】
  • HttpContext模块 --- http上下文模块
  • 从零学习大模型(五)-----提示学习(Prompt Engineering)