2、Python / Nodejs / express 访问本地服务器

Python服务器搭建

    1. 安装Python,下载安装:    Python官网 
    2. 添加到系统环境变量:        path C:\Python27;  
    3. 进项目目录,新建文件:     index.html
      hello world
    4. 命令行,进入目录:           cd C:\workplace\python_test 
    5. 命令行启动服务器:           python -m SimpleHTTPServer 8080  建议安装2.7.11,3.5.1无法运行python指令

访问地址:                      http://localhost:8080/index.html 

node服务器搭建

  1.  安装node
  2.  cd进入安装目录,输入npm install依赖包(系统自动配置环境变量)
                  [这样已经可以node指令了]
  3.  新建项目myapp,cd进入项目目录
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

 或者

var http = require('http');

http.createServer(function(req, res) {
    res.writeHead(200, {'Content-Type':'text/plain'});
    res.end('Hello World\n按ctrl c重启服务器');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337');

 

 

express(应用生成器)服务器搭建

  1. 安装Express(已经安装了node):       npm install express-generator -g
  2. 进入目录,创建项目,项目会自动创建:                                                       cd C:\workplace
    1.                                                      express  myapp(express -e blog支持ejs模板引擎)
  1. 进入项目目录,安装依赖:

                                                           cd myapp
                                                           npm install

  2. 启动应用:                                          set DEBUG=myapp& npm start
  3. 浏览器中打开网址                                 http://localhost:3000/ 

  

转载于:https://www.cnblogs.com/tabCtrlShift/p/5579758.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值