Doron
Doron

Reputation: 273

Yeoman generator using gulp and angular with express server

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');
});

Upvotes: 3

Views: 5428

Answers (2)

Preview
Preview

Reputation: 35806

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

Upvotes: 8

Cluk3
Cluk3

Reputation: 93

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.

Upvotes: 0

Related Questions