AngularJS 高级程序设计
遇到问题:安装web服务器
var connect = require("connect");
connect.createServer( connect.static("../angularjs") ).listen("5000");
命令报错如下:
connect.createServer( connect.static("../angularjs") ).listen("5000");
^
TypeError: Object function createServer() {
function app(req, res, next){ app.handle(req, res, next); }
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
return app;
} has no method 'static'
at Object.<anonymous> (G:
odeserver.js:3:37)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
网上查找发现:createServer 已过时
新的创建server的方式
https://github.com/senchalabs/connect
var connect = require('connect');
var http = require('http');
var app = connect();
// gzip/deflate outgoing responses
var compression = require('compression');
app.use(compression());
// store session state in browser cookie
var cookieSession = require('cookie-session');
app.use(cookieSession({
keys: ['secret1', 'secret2']
}));
// parse urlencoded request bodies into req.body
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));
// respond to all requests
app.use(function(req, res){
res.end('Hello from Connect!
');
});
//create node.js http server and listen on port
http.createServer(app).listen(3000);
然后发现可以用 express
首先安装express:
npm install express
然后启动服务:
var express = require('express');
var app = express();
var pathname = "AngularJS";
app.use(express.static(pathname));
console.log(pathname);
app.listen(3000);
console.log('3000');