Yeoman inside ExpressJS Yeoman inside ExpressJS angularjs angularjs

Yeoman inside ExpressJS


I would recommend this structure for yeoman + expressjs:

mkdir appcd appyeoman angularexpress .

So your dir tree should look like this:

.├── app│   ├── 404.html│   ├── favicon.ico│   ├── index.html│   ├── robots.txt│   ├── scripts│   │   ├── controllers│   │   │   └── main.js│   │   ├── vendor│   │   │   ├── angular.js│   │   │   ├── angular.min.js│   │   │   ├── es5-shim.min.js│   │   │   └── json3.min.js│   │   └── yeoman-test.js│   ├── styles│   │   └── main.css│   └── views│       └── main.html├── app.js├── Gruntfile.js├── package.json├── public│   ├── images│   ├── javascripts│   └── stylesheets│       └── style.css├── routes│   ├── index.js│   └── user.js├── test│   ├── lib│   │   └── angular-mocks.js│   └── spec│       └── controllers│           └── main.js├── testacular.conf.js└── views    ├── index.jade    └── layout.jade

You can remove the now redundant public directory (we're going to serve from app instead):

rm -rf public

And now in app.js, you need to change which dir to serve static files from. Change this line:

app.use(express.static(path.join(__dirname, 'public')));

to this:

app.use(express.static(path.join(__dirname, 'app')));

And that should be about it. There's one careat in that you now have two "index" files -- one in views/index.jade, and the other in app/index.html. Removing the app/index.html currently breaks yeoman, so my advice is to get rid of the route for app/index.jade and just make edits to index.html.

Hope this helps!


Here is another slightly different setup

yo angular

update Gruntfile.js to change config from 'app' to 'public'.

then do

express .

open app.js and ensure there is no route mapping like this app.get('/', routes.index);This is so node server would actually serve up index.html, the same file that loads up when running "grunt server".

Now go ahead and delete public directory and then move app directory to public

rm -rf publicmv app public


This project seems to cover all of the requirements (and even has optional support for MongoDB): https://github.com/DaftMonk/generator-angular-fullstack

I've just tried it locally and it works:

npm install -g generator-angular-fullstackyo angular-fullstack [appname]

See the GitHub page for more info.