Ich bin neu in Node.js und Express. Ich möchte eine grundlegende AngularJS-Anwendung erstellen, aber ich weiß nicht, wo ich anfangen soll. Hier wird die Dateiorganisation ich erreichen möchte:Create basic app - 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
Das erste, was ist es möglich, das zu tun?
Grundsätzlich ist die index.html
Datei, wo ich die ui-view
meiner eckigen Anwendung definiere.
Mein Hauptproblem ist, dass ich nicht herausfinden kann, wie mein Knoten Server in server.js
einrichten ... Hier ist, was ich habe, aber um ehrlich zu sein verstehe ich nicht alle Linien ...
// 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");
Und in routes.js
die folgende Methode, die ich exportieren:
var exports = module.exports = {};
exports.index = function(req, res){
res.render('index');
};
ich schon ejs
Installateur, aber ich bin mir nicht sicher, was damit zu tun ... ich bin ein wenig verloren, so wäre jede Hilfe dankbar sein;)
Haben Sie sich Samen angesehen? Like: https://github.com/meanie/express-seed – Alan
Ich werde es morgen gehen danke;) –