Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor Npm-module client-side?

Tags:

npm

client

meteor

Is it possible to use Npm-Modules on client-side?

More specifically:

I want to use node.js built-in crypto-module for encrypting a password the user enters and then send the encrypted password with a signature(/hmac) to my server.

I need to do it that way, because I must be able to retrieve the original password server-side, because afterwards I'm going to send it to a ldap-server, because the user should authenticate with the same username/password he is registered with on that server.

This is what I did:

created in packages/crypto/: -package.js:

Package.on_use(function(api) { api.add_files('crypto.js',['server','client']);});

-crypto.js: crypto = Npm.require("crypto");

It works fine on the server, but on the client it says "Reference Error: Npm is not defined". So, is it possible to use the crypto-module on client-side?

Are there any alternatives for achieving this goal?

Thank you!

Edit: Is there any good alternative for getting the password to the server in a secure way, so that the server can retrieve the original password? I think doing the ldap()-request on the client-side (like: if(checkLdap(usrname,password)){<login>} else{fail}) can be easily bypassed?

like image 648
Peter W Avatar asked Jun 12 '13 15:06

Peter W


People also ask

How do I use npm on meteor JS?

To use an npm package from a file in your application you import the name of the package: import moment from 'moment'; // this is equivalent to the standard node require: const moment = require('moment'); This imports the default export from the package into the symbol moment .

What is meteor in npm?

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node. js and general JavaScript community.

How to import npm package in project?

Run the command npm install (without any arguments) in the directory where the package. json file is located. That will install ALL packages listed in package. json into a node_modules folder in the same directory.

How to use packages from npm?

To create a package. json file, run npm init in the root folder of your project. After running this command, it asks you for some data about your project, you can choose to answer them or just press enter to set the data values to default. You can also execute the command npm init -y to create the package.


2 Answers

You can try to add the js-files you need on client-side from .npm folder under crypto's package directory. So, your package.js file might look like this:

Package.describe({
  summary: 'Description of your crypto package'
});

Npm.depends({
  'crypto': '1.0.0'
});

Package.on_use(function (api) {
  api.add_files('crypto.js', 'server');
  api.add_files('.npm/node_modules/crypto/crypto.js', 'client');
});
like image 114
th0r Avatar answered Oct 31 '22 22:10

th0r


You can use https://github.com/elidoran/cosmos-browserify now to archive this. I used wrapped packages before and it was real pain to update them and to create new ones. Now with browserify support I can include library with just several lines of code. See their example how to do it. I don't publish it here as it may be subject of change.

like image 31
Igor Loskutov Avatar answered Oct 31 '22 20:10

Igor Loskutov