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

linux安装nodejs

写在前面

因为工作需要,需要使用到nodejs,所以这里简单记录下学习过程。

1:安装

wget https://nodejs.org/dist/v14.17.4/node-v14.17.4-linux-x64.tar.xz
tar xf node-v14.17.4-linux-x64.tar.xz
mkdir /usr/local/lib/node // 这一步骤根据具体的改就行,后面记得改成你本地的
mv node-v14.17.4-linux-x64 /usr/local/lib/node/nodejssudo vim /etc/profile
export NODEJS_HOME=/usr/local/lib/node/nodejs
export PATH=$NODEJS_HOME/bin:$PATHsource /etc/profile

最后查看:

[root@localhost bin]# node -v
v14.17.4
[root@localhost bin]# npm -v
6.14.14

设置淘宝源,加速包下载:

npm config set registry https://registry.npm.taobao.org/
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm config get registry // 查看源

2:测试项目

[root@localhost firstNodeJs]# 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 init` 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: (firstnodejs) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /root/nodejs/firstNodeJs/package.json:{"name": "firstnodejs","version": "1.0.0","description": "","main": "index.js","scripts": {"test": "echo \"Error: no test specified\" && exit 1"},"author": "","license": "ISC"
}Is this OK? (yes) yes
[root@localhost firstNodeJs]# ls
package.json
[root@localhost firstNodeJs]# ls
package.json
[root@localhost firstNodeJs]# vim hello.js
[root@localhost firstNodeJs]# cat hello.js 
console.log('hello from node');
[root@localhost firstNodeJs]# node hello.js 
hello from node

测试一个http的:

[root@localhost firstNodeJs]# vim myhttp.js
[root@localhost firstNodeJs]# node myhttp.js 
server is running...[root@localhost firstNodeJs]# cat myhttp.js 
const http=require('http');
const server=http.createServer();server.on('request',function(request,response) {response.end("<h1 style='color:red;'>hellooooooooo!!!</h1>");		
})
server.listen(3001,function() {console.info('server is running...');
})
http://www.lryc.cn/news/223972.html

相关文章:

  • 第1天:Python基础语法(一)
  • ppt聚光灯效果
  • 图文解析 Nacos 配置中心的实现
  • P1918 保龄球
  • SAP-PP-报错:工作中心 7333_JQ 工厂 7331 对任务清单类型 N 不存在
  • MySQL -- 用户管理
  • IOS浏览器不支持对element ui table的宽度设置百分比
  • Vue+OpenLayers 创建地图并显示鼠标所在经纬度
  • 01-编码-H264编码原理
  • RxJava/RxAndroid的操作符使用(二)
  • 【C语法学习】20 - 文件访问顺序
  • Etcd 常用命令与备份恢复
  • 获取任意时间段内周、季度、半年的二级联动
  • 前端面试系列之工程化篇
  • 京东按关键词搜索商品列表接口:竞品分析,商品管理,营销策略制定
  • Microsoft Dynamics 365 CE 扩展定制 - 9. Dynamics 365扩展
  • 多篇论文介绍-Wiou
  • Django介绍,安装,创建
  • Java通过javacv获取视频、音频、图片等元数据信息(分辨率、大小、帧等信息)
  • flask和fastapi的区别以及demo实现
  • python特殊循环队列_队中元素个数代替队尾指针
  • 什么是观察者模式?用 Python 如何实现 Observer(观察者或发布订阅)对象行为型模式?
  • pytorch直线拟合
  • 相机传感器
  • 大语言模型的关键技术
  • uniapp使用vur-cli新建项目并打包
  • 后台管理系统解决方案-中大型-Vben Admin
  • 通俗理解repartition和coalesce区别
  • 优雅设计之美:实现Vue应用程序的时尚布局
  • 05预测识别-依托YOLO V8进行训练模型的识别——对视频中的目标进行跟踪统计