编译打字稿文件后,我在下一个结构中得到js文件:
main directory
public
api
controllers
data-controller.js
app.js
package.json
...
app.json 代码是:
Object.defineProperty(exports, "__esModule", {
value: true
});
const express = require("express");
const bodyParser = require("body-parser");
const data_controller_1 = require("./public/apì/controllers/data-controller");
const cors = require("cors");
let dataController = data_controller_1.DataController.bootstrap();
const options = {
allowedHeaders: ["Origin", "X-Requested-With", "Content-Type", "Accept", "X-Access-Token"],
credentials: true,
methods: "GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE",
origin: "http://127.0.0.1:3000",
preflightContinue: false
};
const main = express();
main.get('/', function (req, res) {
res.send('hello world11');
});
main.use(cors());
main.options("*", cors(options));
main.use('/data', dataController.GetRouter());
main.use('/', function (req, res) {
res.send('hello world11');
});
main.use(bodyParser.json());
main.use(bodyParser.urlencoded({ extended: false }));
//main.listen(5000);
main.listen(process.env.PORT || 3000, function () {
console.log("SUCCESSFULLY");
});
package.json 是:
{
"name": "sb-admin-bs4-angular-8",
"version": "7.0.0",
"license": "Apache",
"scripts": {
"ng": "ng",
"start": "node --harmony dist/src/server.js",
"build": "ng build --configuration=production",
"test": "ng test",
"test-ci": "TEST_CI=true ng test",
"e2e": "ng e2e",
"web": "npm run server && npm run css && npm run html && npm run scss && npm run ico",
"ico": "copyfiles src/**/*.ico dist",
"html": "copyfiles src/**/*.html dist",
"css": "copyfiles src/**/*.css dist",
"server": "copyfiles src/**/server.js dist",
"scss": "copyfiles src/**/*.scss dist",
"clean": "npm cache clean --force",
"lint": "ng lint"
},
"main": "./dist/server.js",
"private": true,
"dependencies": {
"@types/cors": "^2.8.5",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.0.0",
"express": "^4.17.1",
"mongoose": "^5.6.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.800.0",
"@angular/language-service": "8.0.0",
"@types/jasmine": "2.8.9",
"@types/jasminewd2": "2.0.5",
"@types/node": "10.12.2",
"codelyzer": "^5.0.1",
"jasmine-core": "3.3.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "^4.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "2.0.4",
"karma-jasmine": "1.1.2",
"karma-jasmine-html-reporter": "1.4.0",
"protractor": "5.4.1",
"ts-node": "7.0.1",
"tslint": "5.11.0"
},
"engines": {
"node": "~10.16.0",
"npm": "~6.4.1"
}
}
数据控制器代码为:
class DataController {
}
exports.DataController = DataController;
执行节点应用程序时出现错误.js => 错误:找不到模块"./public/apì/controllers/data-controller">
我为什么得到它?我有哪种解决方案?
// datacontroller file
class DataController {
}
module.exports = DataController;
// app.js file
const DataController = require("./public/apì/controllers/data-controller");
let dataController = new DataController();
dataController = dataController.bootstrap();