首先需要express插件:sudo npm install express
将ionic project的www拷贝至wwwroot,新建server.js:
var express = require('express'),
// employees = require('./routes/employees'),
app = express();
app.use(express.static('www'));
// CORS (Cross-Origin Resource Sharing) headers to support Cross-site HTTP requests
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.get('/', function (request, response) {
response.sendFile(__dirname + "/www/index.html");
});
app.set('port', process.env.PORT || 5000);
app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
then: node server