Lorraine Bernard
Lorraine Bernard

Reputation: 13400

npm for javascript client side code

I was reading a document about npm Developer Guide.
I was wondering if it is possible to write a web client application using javascript/css/html by using npm?
If yes, are there some example on github?

For example my client web application depends on requirejs, jquery, underscore and backbone.
Can I use npm to automatically download, in the vendor directory, the latest version of requirejs, jquery, underscore and backbone ?
If not, are there other tools/methods to accomplish this goal?

Upvotes: 6

Views: 2645

Answers (4)

Wingblade
Wingblade

Reputation: 10093

Long version:

npm is a manager for packages used by nodejs, which is a program for running javascript on serverside.

You can develop your own packages for nodejs and upload them to npm, or use it to install packages released by others, but those are only packages for nodejs, which is serverside, not clientside. So no, you cant use npm for what you want.

Version for really lazy people:

No, because npm is for nodejs, which is serverside, and thus it has nothing to do with clientside applications.

I hope this answers your question.

Upvotes: -3

austincheney
austincheney

Reputation: 1199

An example is my Pretty Diff tool. It works equally well on the client side and I distribute it via NPM. A well written JavaScript application will run absolutely anywhere there is a JavaScript interpreter regardless of the environment. The way to accomplish this is to separate the application code from any APIs. In the case of my application I use the following APIs:

  • DOM - web browser
  • WSH - Windows command line
  • Node.js - Node.js

Upvotes: 0

elclanrs
elclanrs

Reputation: 94101

Okay, now your question becomes clear. Yes, you can use NPM to help you develop JavaScript for the front-end. There are lots of tools available that will make your workflow much smoother. I mentioned jshint and uglifyjs already, but you have grunt to do a bunch of useful tasks, less and sass compilers, and the list goes on. To manage dependencies in CommonJS you'd typically use a package.json.

Upvotes: 1

whostolemyhat
whostolemyhat

Reputation: 3123

Yeoman uses a package manager called Bower to manage dependencies - the Bower Github page gives an example of downloading jQuery for a project, so this might be useful for your projects.

Upvotes: 6

Related Questions