meteor deploy npm packages - node.js

I use multiple npm packages in my meteor application, for instance the 'knox' package for amazon s3 access.
On my local system I don't have any problems, because I have the 'knox'- npm package installed on my system. But on the server this is obviously not the case.
I have read different suggestions what I could do:
1)
Install the npm module into the /public folder of my application
- unfortunately I don't know how to do that.
2)
I followed this tutorial:
NPM Deploy Tutorial
I created packages/knox/package.js packages/knox/knox.js and I am pretty sure I did everything as described in the tutorial but this is not even working locally

Use npm package from Atmosphere. See details on how to use it.

Did you remember to add the knox package to the .meteor/packages file?
The link you shared is pre Meteor 0.6.5, which loaded all packages in packages/ automatically. Now, you need to specify them individually.

Related

How to install just node modules without internet

There is a way to install npm package to a machine which doesn't have internet acccess is, using npm pack in machine with internet acces, copying it to machine without internet and running npm install <tar> in it. But npm pack, packs whole project.
But I want to manage and install the modules myself, without the opportunity for the developers to add/remove any modules. So I just want node_modules to be packaged. And then want to install it to machine without internet.
For example when developer push his/her commits to origin, I want to get node_modules from ftp etc. and codes from GitLab then go on continuous integration with this static node_modules.
How can I do that?
There is a solution to manage the modules yourself: you can store your node_modules in its own repo in which your developers will only be able to clone/get the repo and not contribute/modify it.
Hope this helped you
This can be done, please look at Installing a local module using npm? . You can FTP or whatever to get the packages and install them using npm.

How to zip a nodejs server app?

I have to create a zip file of my whole nodejs server app.
I should be able to unzip it and run it, without installing dependencies and apps.
It should not be a binary file.
The dependencies should be flattened.
How to do this thing ?
Generally, a Node.js app has its dependencies installed in the node_modules directory in the project root.
So, after running npm install (or npm install --production), you should be able to zip up the project directory and that should be all you need.
If any of your dependencies in node_modules are native addons, then you will not be able to install them on a different architecture or OS. If there are native addons, you will also want to make sure your target machine has the same version of node installed as the machine where you created the zip file. (It's a good idea anyway, if you can, to make sure the node version on the target machine is the same as the source machine.)
One obvious requirement of the target host if you do as I describe above is that node is already installed there. Not sure if that's OK for your use case or not, but sounds like it probably is?
Thank you, all of you for your help.
I got the solution for my question.
I am using npm pack to pack the nodejs app.
To pack nodejs app with some dependencies like morgan, express we need to use npm bundle it helps to include the other module required for node js app.
With this, we don't need to perform npm install.
We just have to install bundle and then include bundleDependencies field including the name of required module in package.json.
And then perform then run the command npm pack. It will create a tar file just copy this file in other folder and uncompress it and run the server starting file.
The place where you are going to run the nodejs file, there nodejs app should be installed
I think you might be looking for this: https://github.com/nexe/nexe
Nexe is a command-line utility that compiles your Node.js application into a single executable file.

What is the difference between installing a package locally and globally using npm?

What is the difference between installing a package locally and globally using npm?
From my understanding:
Locally install: npm install <package>
This package/module will find on your local node_modules folder and
can only be usable for this project.
This package/module can be accessible in using require("package")
from code.
This package/module can't be accessible in command line interface.
Globally install: npm install <package> -g
This package/module will find on where node is installed in your machine like /usr/local and can be usable everywhere.
This package/module can't be accessible in using require("package")
from code.
This package/module can be accessible in command line interface.
Please let me know. If I could misunderstand anything here. Thanks!
You are correct except for 1 point.
The local packages exposing CLI utilities can be accessed from the command line. Newer versions of NPM create this .bin/ directory inside the local node_modules/.
Whenever you try to use a tool (let's take babel for example), if you use it from the command line and you have it installed in your project, npm will properly identify that package and run it's CLI for you.
Here's a useful article on the topic.
http://www.2ality.com/2016/01/locally-installed-npm-executables.html
Global modules are mostly tools like gulp, yoman or any other module you use in your daily work.
Local modules are the dependencies of your project. You should never depend on a global module in your project. Even dependencies as gulp should be a local dependency in your dev-dependency section.

Where does meteor install npm packages referenced in packages.json?

After meteor installs npm packages:
npm: updating npm dependencies -- winston...
Npm.require results in module not found error, by inspecting the code and debugging via node-inspector, I discovered that putting a standard node_modules folder (installed via npm install) in .meteor folder in the root of my meteor app folder gets it to find it.
However when deploying to meteor.com or using any automated build-pack (like Heroku's) this might not be possible, I would rather have a scenario where I can link the automatically downloaded modules to the paths Npm.require looks in.
Any idea where it downloads the packages?
Thanks
For meteorite packages this would be:
/path/to/your/project/packages/package_name/.npm/package/node_modules/
For core meteor packages I guess this is
~/.meteor/packages/package_name/hash/npm/node_modules/

cannot find module express, how to install it to make it globally available?

I want to experiment with some node.js stuff and I installed it yesterday following someone's instructions on the web which got it up and running, and I got the standard Hello World web page up on the screen.
I now went to move onto another example, but in order to not clutter my home directory, I created a directory off of it (~/node) and created the files I needed in there. Low and behold, when it came time to run the service, I got no joy stating the express module couldn't be found.
The instructions told me to install express using the -g flag, but that didn't help. I even ran it again without any luck.
Now I've found this:
Cannot find module `express` | socket.io [node.js]
and it appears I have to install it again under the current directory. I have done that and it works. Is it the case it has to be installed under each directory that I want services running from? It seems an unnecessary duplication.
edit:
Not knowing much about js I thought I would go digging and found
app.use(express['static'](__dirname ));
and have realised this is probably the cause of my problem. Further research has found this: http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders and if I install it once in a higher level directory, that should 'solve' my problem. I'm not going to bother about uninstalling the module, but for my next project I will try it and see how it goes.
I don't know why the original author suggested the -g flag when installing express, since it hasn't seemed to work for me.
NPM is a really nice tool, allowing you to install node.js modules locally and globally.
Local module installation
If you want to use a module for your project, you have to install it locally.
That's why npm creates a subdirectory called node_modules inside your project directory.
If you use the same module for two different projects, npm will download the module and install it twice. That's perfectly normal, it helps you manage different versions of the same dependency.
The best way to manage dependencies and install modules for a specific project is to fill the package.json with your dependencies and install them using
npm install
inside your project directory.
To access your modules in your code, use the require() function.
For example, with expressjs :
var express = require('express');
var app = express();
...
Global module installation
npm allows you to install modules globally as well. But remember that installing a module globally only provides more commands in your terminal, as with expressjs and express(1).
In order to install expressjs globally, run this in your terminal
npm install -g express
If you want to use a globally installed module in a specific project, you also have to install it locally (in your project directory, without -g).
I hope this answers clearly your question.
Express is capable of generating a simple app structure when installed globally. See this link and scroll to Using express(1) to generate an app section. It's a good way to get you started easily.
Take a look into package.json, package.json in nodejitsu
All npm packages contain a file, usually in the project root, called package.json - this file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies
a package.json example:
{
"name": "CRUD",
"description": "A simple CRUD",
"author": "Only for learn",
"dependencies": {
"express": "*",
},
}
so for install the dependencies go to level that package.json is, and run npm install this one will install all the dependencies you need for the project.
EDIT
a package.json interactive guide
I have found that when setting up node.js projects and dependencies, using Grunt [http://gruntjs.com/] has a lot of advantages. Although there are lots of different ways to setup a node and express project there is a lot to be said for using the Douglas Crockford approach and 'going with the grain'. In this case Grunt is the grain as it is becoming the de-facto standard for setting up a node project and there are existing templates for the most common types of node.js projects. You can find Grunt Express here [https://github.com/blai/grunt-express].
In this case Grunt would provide you with a project structure consistent with others, setup dependencies file for the node package manager and auto generate the express project for you. Packages are kept in a node_modules directory. If you are familiar with maven you might recognize the 'convention over configuration approach'.

Resources