zoukankan      html  css  js  c++  java
  • 2、Python / Nodejs / express 访问本地服务器

    Python服务器搭建

      1. 安装Python,下载安装:    Python官网 
      2. 添加到系统环境变量:        path C:Python27;  
      3. 进项目目录,新建文件:     index.html
        hello world
      4. 命令行,进入目录:           cd C:workplacepython_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
    ');
    });
    
    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
    按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. 进入目录,创建项目,项目会自动创建: 
    3.                                                      cd C:workplace
                                                             express  myapp(express -e blog支持ejs模板引擎)
    1. 进入项目目录,安装依赖:

                                                             cd myapp
                                                             npm install

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

      

  • 相关阅读:
    课堂练习
    《你的灯亮着吗》第二篇总结
    四则运算2程序
    《你的灯亮着吗》第一篇总结
    四则运算2
    阅读计划
    四则运算
    《人月神话》读后感
    软件演化
    软件测试
  • 原文地址:https://www.cnblogs.com/tabCtrlShift/p/5579758.html
Copyright © 2011-2022 走看看