I used npm to install most of my dependent libraries. Now I would like to add these libraries to my working directory so that another computer can directly run it w/o manually downloading and installing these files. I have seen many projects on github do this.
How should this be done? And which files should I include? Most of my libraries are in /usr/开发者_Python百科local/lib/node/
Create a package.json file that states what your dependencies are then use npm link
to install from that package file.
example package file :
{
"name": "Inventory-System",
"description": "Manage Inventory web app",
"version": "0.0.1",
"author": "Raynos",
"dependencies": {
"now": "0.5.3",
"backbone": "0.3.2",
"cradle": "0.5.5",
"supervisor": "0.1.2",
"less": "1.0.41",
"ejs": "0.4.1"
}
}
This allows you to declaratively define your dependancies then installing your library because as simple as npm link
.
You can also go further and publish your own library through npm
then just call npm install myLibrary
on another computer.
All you need to run a stand-alone node.js application is your application code and the node binary executable--typically found under /usr/local/bin--as it already contains all of the "native" modules. (See below for a list.) If your application requires other libraries than these, you'd need to provide them as part of your application.
If you choose to deploy your application to a server using npm, the method outlined below by @Raynos will work nicely.
On the other hand if you choose to deploy your application to a server via git or as an archive, you'll need to provide all of the libraries required by your application as well as their dependencies.
One way to do this is to install/copy all required libraries under the 'node-modules' directory in your application's home directory.
As of Node@0.4.7, the native modules include: assert, buffer, child_process, console, constants, crypto, dgram, dns, events, freelist, fs, http, https, module, net, os, path, querystring, readline, repl, stream, string_decoder, sys, timers, tls, tty, url, util and vm.
See http://nodejs.org/docs/v0.4.7/api/modules.html for further information.
精彩评论