node.js常用dos环境命令

来源:互联网 发布:qt mysql数据库 编辑:程序博客网 时间:2024/06/05 08:17

1输入node -v,测试是否安装成功,会输出版本信息。

2.npm install -g supervisor :自动监听服务器修改

3.npm uninstall module-name 命令来卸载 Node.js 模块; 

4.npm help command 可查看某条命令的详细帮助


  • ctrl + c - 退出当前终端。
  • ctrl + c 按下两次 - 退出 Node REPL。
  • ctrl + d - 退出 Node REPL.
  • 向上/向下 键 - 查看输入的历史命令
  • tab 键 - 列出当前命令
  • .help - 列出使用命令
  • .break - 退出多行表达式
  • .clear - 退出多行表达式
  • .save filename - 保存当前的 Node REPL 会话到指定文件
  • .load filename - 载入当前 Node REPL 会话的文件内容
创建一个http服务器:

(1)使用 require 指令来载入 http 模块,并将实例化的 HTTP 赋值给变量 http

var http = require("http");
(2)使用 http.createServer() 方法创建服务器,并使用 listen 方法绑定 8888 端口。 函数通过 request, response 参数来接收和响应数据。

var http = require('http');http.createServer(function (request, response) {    // 发送 HTTP 头部     // HTTP 状态值: 200 : OK    // 内容类型: text/plain    response.writeHead(200, {'Content-Type': 'text/plain'});    // 发送响应数据 "Hello World"    response.end('Hello World\n');}).listen(8888);
(3)使用 node 命令执行以上的代码:

node server.js