有人可以帮助我为什么默认路由在我的Mean App中不起作用,但下一个路由工作
当我打开 http://localhost:3000 时,我无法看到任何输出,但我已经在route.js中定义了正在运行的路线
var express = require('express');
var cors = require('cors');
var bodyparser = require('body-parser');
var mongoose = require('mongoose');
var path = require('path');
const port = 3000;
app.get('/', function (req, res) {
res.send('Test');
console.log('Opened the root path');
});
当我使用 http://localhost:3000/main 打开页面时,我能够看到输出并在控制台中写入日志
const express = require('express');
const router = express.Router();
router.get('/main', function (req, res, next) {
res.send('This is the Admin Landing Page');
});
router.get('/install', function (req, res, next) {
res.send('This is the Install Landing Page');
console.log('Opened the Install path');
});
module.exports = router;
答案 0 :(得分:0)
看起来你粘贴的代码是完整版,而且它不可运行,因为:
app
变量。start the http server
。告诉根本原因你的代码有什么问题真的很难。以下代码适用于我:
const express = require('express');
const port = 3000;
let app = express();
app.get('/', function (req, res) {
res.send('Test');
console.log('Opened the root path');
});
let server = require('http').createServer(app);
server.listen(port, function() {
console.log('Server started');
});