corry
corry

Reputation: 1529

How to define the correct path in Node Express to use bower_components?

I have a trouble with defining correct path for bower components. Here is my file structure:

projectName
    | - client/
        | - app/
        | - bower_components/
        | - node_modules/ (grunt tasks)
        | - test
        | - Gruntfile.js
        | - package.json
        | - bower.json
    | - server/
        | - server.js
    | - node_modules/ (modules for server side)
    | - package.json

and my code in server.js file:

var express = require('express');
var mysql = require('mysql');

var app = express();
app.use('/', express.static('../client/app'));
app.use('../client/bower_components',   express.static('../client/bower_components/'));

Is it possible to correctly define path for bower_components in hirerachy like this one?

Upvotes: 0

Views: 1440

Answers (1)

peteb
peteb

Reputation: 19418

Add it as a static directory just like you have done so with your actual application root, your current implementation is serving it from /client/bower_components/ which means that your html files would also have to reference your bower modules at that address.

Change your bower_components to be the following:

app.use('/bower_components', express.static('../client/bower_components'));

Then in your html files just reference /bower_components/<module_path>

Upvotes: 1

Related Questions