Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use npm package on client side

is there a way I can use an npm package on the client side? For example, I want to use the dateformat(https://www.npmjs.com/package/dateformat) package in my client side javascript file

like image 329
Trung Tran Avatar asked Jan 28 '16 21:01

Trung Tran


People also ask

How do I use npm client side packages?

Using npm to install dependenciesExecute command npm install . This command would read package. json and install dependencies jquery and bootstrap. A new directory called node_modules should have been created and directories jquery and bootstrap should have been created inside node_modules .

Can npm packages be used in the browser?

If you simply want to test out some NPM modules right inside your browser without setting up an entire app, you can use Browserify in three simple steps to use NPM modules.

How do you use require in client side?

Use require() on client side It is possible to use require() on the client browser side. For example: var myClass = require('./js/myclass. js');


1 Answers

If you want to use npm on the client you may consider using browserify which is designed for that purpose. The node module system is not compatible with browsers so browserify transpiles the javascript into something that will work. Hence the name : browserify.

like image 133
chriskelly Avatar answered Oct 11 '22 21:10

chriskelly