Rhushikesh
Rhushikesh

Reputation: 3700

unable to load node_modules files for angular2 in nodejs app

I am developing a app in nodejs with angular2. in which i have link the node_modules file in my index.html page. but when i load my app it unable to load the angular2 file form moude_modules flolder:

here is my server.js config for static content which in app folder

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

here is my index.html link

<script src="../node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="../node_modules/systemjs/dist/system.src.js"></script>
    <script src="../node_modules/rxjs/bundles/Rx.js"></script>
    <script src="../node_modules/angular2/bundles/angular2.dev.js"></script>

here is my folder structure :

-app
|-server.js
-node_modules
-public
|-index.html

its giving me error:

enter image description here

please correct me to serve those file.

Upvotes: 1

Views: 2127

Answers (1)

trquoccuong
trquoccuong

Reputation: 2873

You can setting multi folder express_static

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

inside index.html

<script src="/angular2/bundles/angular2-polyfills.js"></script>
<script src="/systemjs/dist/system.src.js"></script>
<script src="/rxjs/bundles/Rx.js"></script>
<script src="/angular2/bundles/angular2.dev.js"></script>

Upvotes: 4

Related Questions