版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chang_li/article/details/89706922
安装
cmd窗口命令测试
npm -v
node -v
修改环境变量
在安装目录下创建两个文件夹node_global
和node_global
修改个人环境变量的path为D:\software\nodejs\node_global\node_modules
系统path不要改。
cmd执行如下命令
npm config set prefix "D:\software\nodejs\node_global"
npm config set cache "D:\software\nodejs\node_global"
执行测试:npm install express -g # -g是全局安装的意思
可以看到上面指定的路径下D:\software\nodejs\node_global\node_modules出现了新安装的模块。
参考:nodejs安装
测试
创建helloworld.js
//require表示引包,引包就是引用自己的一个特殊功能
var http = require("http");
//创建服务器,参数是一个回调函数,表示如果有请求进来,要做什么
var server = http.createServer(function(req,res){
//req表示请求,request; res表示响应,response
//设置HTTP头部,状态码是200,文件类型是html,字符集是utf8
res.writeHead(200,{"Content-type":"text/html;charset=UTF-8"});
res.end("hello,world!");
});
//运行服务器,监听3000端口(端口号可以任改)
server.listen(3000,"127.0.0.1");
cmd到响应的目录下执行node helloworld.js
访问http://127.0.0.1:3000
idea安装node环境
搜索nodejs插件,安装重启即可
新建工程,已经可以创建nodejs工程了。
一路next,创建成功。启动脚本,访问localhost:3000