這是一個基本的應用程序我已經得到了一個蒙戈DB基本app + express + mongodb +如何不使用端口?
如果我去無論是在使用意見明確了建立和航線,也做一些查詢/ hello.html的將被顯示在瀏覽器。 如果我去http://localhost:8080/test
'這是一個測試頁'將被顯示在瀏覽器中。
我的問題是爲什麼我必須在地址中指定端口8080?或換句話說,如何在不指定端口的情況下顯示我想要的地址http://localhost/
?
我知道我可以通過改變8080這裏的值更改端口
app.listen(8080);
下面
基本應用:
var express = require('express'),
app = express(),
cons = require('consolidate'),
crypto = require('crypto'),
MongoClient = require('mongodb').MongoClient;
app.engine('html', cons.swig);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
MongoClient.connect('mongodb://localhost:27017/m101', function(err, db) {
if(err) throw err;
//set up a route to go to the page http://localhost:8080/ to see 'This is a test Page'
app.get('/', function(req, res){
db.collection('hw1_3').findOne(function(err, doc) {
//do stuff here
return res.render('hello', { "name" : decrypted });
});
});
//set up a route to go to the page http://localhost/test to see 'This is a test Page'
app.get('/test', function(req, res){
return res.send('This is a test Page!!', 200);
});
app.listen(8080);
console.log('Express server started on port 8080');
});