我有一个html页面和serviceController.js,我需要通过node js自动运行该应用程序.很抱歉这个幼稚的问题,但无法运行.我的serviceController.js看起来像这样:
var app = angular.module("app", []);
app.controller('serviceController', ['$scope', '$interval','$http', function($scope, $interval, $http)
{ $scope.service1 = {//and so on..
}
我正在跟踪一个示例,并且尝试了以下操作:创建了package.json:
{ "name": "express-html",
"version": "0.0.1",
"dependencies": {
"express": "^4.11.0"
}}
我的server.js看起来像这样:
var express = require("express");
var app = express();
var path = require("path");
app.get('/',function(req,res){
res.sendFile(path.join(__dirname+'/index.html'));
});
app.listen(3000);
console.log("Running at Port 3000");
但是,当我尝试使用以下命令从终端启动应用程序时:node server.js.我收到以下错误:
(function (exports, require, module, __filename, __dirname)
{ var app = angular.module("app", []);
^ReferenceError: angular is not defined at Object.<anonymous> (/Users/dem/Desktop/frontend/task3/serviceController.js:1:81)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/dem/Desktop/frontend/task3/server.js:5:19)
at Module._compile (module.js:570:32)
请指导!
解决方法:
app.use(“ /”,express.static(__ dirname));用它代替
res.sendFile(path.join(__ dirname’/index.html’));