YeppThat'sMe YeppThat'sMe - 1 year ago 119
Javascript Question

Nodejs / HapiJs with Angular.js

can someone explain me how to combine nodejs (hapi server) with AngularJs? I thought I can just catch every request made to my Hapi server and react to those requests using angularjs' routes / REST etc…

The server is running and serves me my index.html as I expect, but however I am to stupid to hook in my app.js for the angular stuff. I guess my approach is completely wrong.


method: 'GET',
path: '/{p*}',
handler: function (request, reply) {

index.html (header)

<script src="CDN/angular.min.js"></script>
<script src="./app.js"></script>

Inline AngularJs code in my index.html works properly. I'm thankful to every response or some resources I can look at.

Answer Source

your approach is for an api and not for serving static files. Server static files like this:

// static file
    method: 'GET',
    path: '/{param*}',
    handler: {
        directory: {
            path: Path.join(__dirname, 'public/app')

see more info here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download