我試圖使用express將代碼拆分爲兩個。 這裏是什麼我做將express節點js拆分爲兩個
app.js
var express = require('express');
var app = express();
var stud = require('./grades');
var port = process.env.PORT || 3000;
stud.excellence;
app.listen(port);
grades.js
var text = '{ "students" : [' +
'{ "name":"Elsa" , "grade":"70" , "course":"ws" , "year":"2015" },' +
'{ "name":"Anna" , "grade":"80" , "course":"ws" , "year":"2016" },' +
'{ "name":"Anna" , "grade":"86" , "course":"math" , "year":"2014" },' +
'{ "name":"Ron" , "grade":"92" , "course":"math" , "year":"2016" } ]}';
module.exports = function excellence() {
app.get('/getAllExcellenceStudent', function(req, res) {
res.json(text);
})
};
當我想在我的寫作loclhost我http://localhost:3000/getAllExcellenceStudent拿到拿不到/ getAllExcellenceStudent運行
我做錯了什麼?
嘗試刪除行'module.exports = function excellence(){' –