3
votes

I am trying to set up a MEAN stack web app using yeoman with the generator-gulp-angular, which comes without express server. I tried to add express, but I am having trouble with it, the index html in .tmp folder doesn't find any of the bower_components folder items. Anyone have a working example of such setup ?

I added the express server loading file which contains:

app.use(express.static(path.join(rootPath, '/.tmp/serve')));
app.use(express.static(path.join(rootPath, '/bower_components')));
app.use(express.static(path.join(rootPath, '/src')));

app.get('/', function(req, res) {
    res.sendFile('/.tmp/serve/index.html');
});
2
I can't really understand your question since MEAN means (Monogo, EXPRESS, Angular, and Node). So you are not using a MEAN stack. If you are trying to build your own MEAN stack you should check out the mean stack mean.io all this work is already done for you. That's why they made it. Forget about Yeoman and Gulp generators. Start building your app. - Rafael

2 Answers

8
votes

First, you should exploit all the potential of express by using its router, that will allow you to manage easily your routes in separate folders for each subroutine otherwise you can quickly end up with a mess for all the new routines you create.

Serving your client files should be a one-liner by putting them in a specific directory that is easily targetable.

To do something optimised, you'll also have to create a build task that concat and minify all your client files and change their paths in your index.html.


Old user of the angular-fullstack generator and gulp lover, a friend and I came with a new project called generator-bangular. Basically a fullstack generator using angular, gulp and express. It allow you to easily launch a new project with a clean architecture and built-in commands to create everything you need, from a new api route to a directive.

Install it using

npm install -g generator-bangular

And get started by running

yo bangular
0
votes

I can't help you with this specific problem having so few information about your setup, but i really recommend you to use the angular-fullstack generator for your first MEAN app.