我是Node.js和Express的新手。我想創建一個基本的AngularJS應用程序,但我不知道從哪裏開始。這裏是我想實現的文件組織:創建基本應用程序 - MEAN
- public
----- app
---------- components
----------------- component0
----------------------- c0controller.js
----------------------- c0.html
----------------------- c0Service.js
----------------- component1
----------------------- c1controller.js
----------------------- c1.html
----------------------- c1Service.js
---------- assets [...]
----- index.html
----- app.js
----- module.js
- node_modules [...]
- server.js
- route.js
首先,是否可以這樣做?
基本上,index.html
文件是我定義我的角度應用程序的ui-view
的地方。
我的主要問題是,我不能找出如何設置在server.js
我的節點服務器...這是我有但說實話,我不明白,每行...
// set up ========================
var express = require('express');
var app = express(); // create our app w/ express
var mongoose = require('mongoose'); // mongoose for mongodb
var morgan = require('morgan'); // log requests to the console (express4)
var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
var routes = require('./routes.js');
// configuration =================
mongoose.connect('mongodb://localhost/test'); // connect to mongoDB database
app.set('views', __dirname + '/public/app');
app.set('view engine', 'html');
app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());
app.get('/', routes.index);
app.get('*', routes.index);
// listen (start app with node server.js) ======================================
app.listen(8080);
console.log("App listening on port 8080");
而在routes.js
我導出以下方法:
var exports = module.exports = {};
exports.index = function(req, res){
res.render('index');
};
我已經安裝人員ejs
,但我不知道該怎麼用它做什麼......我有點失去了任何幫助,將不勝感激; )
你看過種子嗎?像:https://github.com/meanie/express-seed – Alan
明天我會給它一個去吧謝謝你;) –