accessing node modules from index.html from public folder

How can i access node_modules like angular from my index.html file

File structure like so

node_modules

public

  • jsfolder
  • cssfolder
  • index.html

server.js

I know this doesnt work but its what I have so far in index.html

  <script src="../node_modules/angular/angular.js"></script>

I know I shouldnt put node modules in public so do i serve it with node or something.

728x90

1 Answers accessing node modules from index.html from public folder

(A) Best solution for you may be Parcel

(B) But yeah, this is pretty annoying. You're right that you shouldn't have node_modules in public. Unfortunately the real answer isn't a simple one. You should copy the files you need into public/lib using something like Gulp or Webpack.

This guide is pretty good: https://george.webb.uno/posts/gulp-and-npm-for-front-end-web-development

(C) To use a package manager exactly the way you specified, Bower is your friend (https://bower.io/)

Bower is on its way out and you'll want to move to NPM + Webpack eventually. To do that, look at Parcel (https://parceljs.org/)

4 months ago