概述
1、找到官方二进制包,下载 : https://nodejs.org/en/download/
我这里是centos的linux环境
2、安装
# 先做软链接
[root@cicd local]# ln -s /usr/local/node/bin/npm /usr/local/bin/npm
[root@cicd local]# ln -s node-v14.15.1-linux-x64/bin/node /usr/local/bin/node
# 再做一个本地软链接
[root@cicd local]# ln -s node-v14.15.1 node
# 再给几个版本解压放到这里(解压略),需要哪个就用软连接指过去
[root@cicd local]# ll
total 0
drwxr-xr-x. 3 root root 62 Dec 2 11:26 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
lrwxrwxrwx 1 root root 13 Dec 2 11:29 node -> node-v14.15.1
drwxrwxr-x 6 500 500 108 Mar 5 2019 node-v10.15.3
drwxr-xr-x 6 1001 1001 108 Oct 7 02:14 node-v12.19.0
drwxr-xr-x 6 1001 1001 108 Nov 16 21:23 node-v14.15.1
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Aug 20 07:04 share
drwxr-xr-x. 3 root root 24 Nov 11 16:06 src
[root@cicd local]# node -v
v14.15.1
[root@cicd local]# npm -v
6.14.8
[root@cicd local]# pwd
/usr/local
3、npm是国外的,更换淘宝镜像源
[root@cicd local]# npm install -g cnpm --registry=https://registry.npm.taobao.org
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/node-v14.15.1/bin/cnpm -> /usr/local/node-v14.15.1/lib/node_modules/cnpm/bin/cnpm
+ cnpm@6.1.1
added 689 packages from 972 contributors in 375.306s
[root@cicd local]#
4、写个测试页面,测试
[root@cicd local]# vim example.js
[root@cicd local]# node example.js &
[1] 19084
[root@cicd local]# Server running at http://0.0.0.0:3000/
[root@cicd local]# netstat -tpln|grep 3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 19084/node
# 这是测试页面内容
[root@cicd local]# more example.js
const http = require('http');
const hostname = '0.0.0.0';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello Worldn');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
访问测试页面
# 访问测试页面
[root@cicd local]# ip a|grep 24
inet 10.0.1.185/24 brd 10.0.1.255 scope global ens192
[root@cicd local]# curl -I http://10.0.1.185:3000/
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Wed, 02 Dec 2020 03:47:04 GMT
Connection: keep-alive
Keep-Alive: timeout=5
[root@cicd local]# curl http://10.0.1.185:3000/
Hello World
[root@cicd local]#
# 关闭测试进程
[root@cicd local]# netstat -tpln|grep 3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 19084/node
[root@cicd local]# kill -9 19084
[root@cicd local]# netstat -tpln|grep 3000
[1]+ Killed node example.js
[root@cicd local]#
浏览器中访问效果
最后
以上就是体贴蜜粉为你收集整理的Vue,Nodejs环境搭建的全部内容,希望文章能够帮你解决Vue,Nodejs环境搭建所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复