Python服务器搭建
- 安装Python,下载安装: Python官网
- 添加到系统环境变量: path C:Python27;
- 进项目目录,新建文件: index.html
hello world
- 命令行,进入目录: cd C:workplacepython_test
- 命令行启动服务器: python -m SimpleHTTPServer 8080 建议安装2.7.11,3.5.1无法运行python指令
访问地址: http://localhost:8080/index.html
node服务器搭建
- 安装node
- cd进入安装目录,输入npm install依赖包(系统自动配置环境变量)
[这样已经可以node指令了] - 新建项目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(应用生成器)服务器搭建
- 安装Express(已经安装了node): npm install express-generator -g
- 进入目录,创建项目,项目会自动创建: cd C:workplace
- express myapp(express -e blog支持ejs模板引擎)
- 进入项目目录,安装依赖:
cd myapp
npm install - 启动应用: set DEBUG=myapp& npm start
- 浏览器中打开网址 http://localhost:3000/