Working with nodejs and mongodb - mongodb

Are there any libraries or frameworks that allow me to work with mongodb and nodejs that don't require a npm install ? More precisely I'm working on windows.For example i managed to find a library for working with websockets(https://github.com/ncr/node.ws.js) and simply requires you to include the file.
Is it absolutely necessary to use a library ? I am asking because all the tutorials use one, doesn't node have a module for this ?

You don't need npm to use most modules - you can download them (e.g. from their GitHub page as a zip file) and then put them in your project folder. Then require them:
var mongodb = require('../lib/module-folder-name');
Some useful libraries:
MongoDB native driver:
https://github.com/christkv/node-mongodb-native
Mongoose, a higher level ORM for MongoDB:
https://github.com/learnboost/mongoose/

evilcelery has the best answer +1 from me;
Most anything you run across for npm will work just as he said, and lib is the best convention to do it with.
To expand on his links a bit The module list he refereed to is found:
https://github.com/joyent/node/wiki/modules
http://search.npmjs.org/ is a bit more user-friendly.
Also if you wish to include things globally similar to npm you can do what it does with things like html and put it in the lib dir where you originally compiled it with the Makefile (note: you may not need to rebuild it but I beleave you do)
There are a lot of mongodb related projects/libs enjoy!
interestingly:
Blockquote Contrary to the belief of many, "npm" is not in fact an abbreviation for "Node Package Manager". It is a recursive bacronymic abbreviation for "npm is not an acronym".
source: https://github.com/isaacs/npm/blob/master/doc/faq.md#readme

You can use builtin net.sockets module
var net = require('net');
var server = net.createServer(); // to listen
var socket = net.socket; // to connect
It might you to work with any network application and write raw requests.
A lot of modules written on js so you can not to install them with npm, but require from your project folder.

I haven't tried it, but this should enable you to get node packages with windows: https://github.com/japj/ryppi . It will require you to download Python.

Related

perl lib issue - not finding lib dir

For years I have been using the following at the top of my scripts:
use lib '/var/www/vhosts/example.com/demo.example.com/cgi-bin/library';
That works fine when the lib is within the same domain space as the calling script.
However, I want to call in from a centralised library so I will have just one place to set db credentials.
So, if I adjust that line to call in from another account on the same server, it cannot find the library.
use lib '/var/www/vhosts/example2.com/demo.example2.com/cgi-bin/library';
Running on plesk, if that may make a difference. Used to run on cPanel and I had no issue.
I would appreciate a pointer, having already read some docs and I am confused.
Only someone with access to the configuration of your web server can answer this for sure, but I'd guess that each of your vhosts is running as a different user and the users can only read files from their own web space.
This approach won't work. If you want to to have a centralised module library then either install the modules that you want in the system module library (i.e. where cpan will install them by default) or create your own new centralised library somewhere that isn't under one of the vhost directories (perhaps under /opt).
However, it's worth noting that best practices for deployment of applications are moving in completely the opposite direction. It's generally considered a good idea for each application to have its own set of dependencies installed in its own module library. Using a cpanfile to record the exact versions of the dependencies that you're using makes this simple.

How to create and compile a custom module in MongooseIM

System Info:
MongooseIM version: 3.0.0
Installed from: pkg
Erlang/OTP version: 18
Ubuntu 16.04
I am having trouble creating a standard base for a custom module. I want to create a simple hello world program as outlined in the documentation for ejabberd.
However, I cannot get it to work for MongooseIM. Are there any instructions for how to do this? As a beginner I am just looking for building blocks to creating my own modules, and everything I look at is a little too complex for what I am trying to achieve at the moment.
Here is the code for my module: (taken from ejabberd) https://docs.ejabberd.im/developer/extending-ejabberd/modules/#mod-hello-world
And here is my log error:
I have added the following line in my config file with all other running modules:
{mod_hello_world, []}
I am assuming it has something to do with the compilation and there being no .beam file created for the modules as well as some syntax errors specific to MongooseIM. I am also unfamiliar with documentation for compiling modules when using a pre-built pkg as opposed to installing from source.
DISCLAIMER: I'm a MongooseIM developer working for Erlang Solutions.
The link you posted hints at the answer to the immediate question:
If you compiled ejabberd from source code, you can copy that source code file with all the other ejabberd source code files, so it will be compiled and installed with them. If you installed some compiled ejabberd package, you can create your own module dir, see Managing Your Own Modules.
MongooseIM (a.k.a. MIM) does not support the latter method of managing modules, i.e. it's not possible to drop source code into some predefined location when MIM is installed from a package and let it just compile and run the module. If we want to write a custom module, we have to build MongooseIM from source.
To be precise, we don't have to build the whole server from source and package it ourselves. We have to, however, clone the repository, place the new module source there (due to build time requirements like header files) and build it there. Once we get a .beam file of the new module we can just drop it into an installed MongooseIM's code path.
To be even more precise, let's say we have installed MIM from mongooseim_3.0.0-1~ubuntu~artful_amd64.deb available from the Downloads page at erlang-solutions.com, therefore we want to build a module compatible with 3.0.0:
Clone MIM: git clone https://github.com/esl/mongooseim
cd mongooseim
git checkout 3.0.0
Place mod_hello_world.erl under ./src/
rebar3 compile
Once rebar3 finishes get ./_build/default/lib/mongooseim/mod_hello_world.beam and copy to the target host where we installed MIM from a package.
Please note, though, that an example taken straight from ejabberd documentation might not work "as is" in MongooseIM. In this simple module, for example, we'll not be able to include logger.hrl as MongooseIM doesn't have such a header file - we would have to -include("mongoose_logger.hrl"). instead.

How to use npm packages with ReasonML?

I'm quite experienced with ReactJS and now I'm trying to learn ReasonML. But one thing that I've been struggling to understand, is how to import npm packages with React/Reason.
The instructions on the website are kinda unclear to me (https://reasonml.github.io/guide/javascript/interop/).
So, if I have a React/Reason project and want to use a npm package, how do I do it? How do I import it, using Reason lang?
First off, thanks for the feedback! I'll make sure to get this improved.
Now, to be able to use a javascript library published on npm, you'll need to either find or make some bindings for it, as a bridge between Reason/BuckleScript and JavaScript. Ideally, the bindings you need have already been written (or generated) and published to npm, but in case it hasn't you'll have to write them yourself.
Most readily available bindings are listed in redex, the package index, and will include instructions on how to use it. But if they don't, all you need to do is run npm install --save <package-name>, as usual, then add the package name to the bs-dependencies array in bsconfig.json (see also the BuckleScript manual). Make sure to run bsb -make-world to get the new dependency built, then you should be able to use the modules exported by the bindings directly.
If there are no bindings, and you want to make your own, all you need to do is add the javascript package as normal using npm install --save <pacakge-name>, then just start writing externals. How to do so is described in the BuckleScript manual. You may also find my FFI cheatsheet useful.
Lastly, you're welcome to join us on our Discord where there's lots of friendly people eager to help!

How to set sass with compass and coffeescript in meanio

I find mean.io (MongoDB Espress Angular Node) very interesting.
I'm used to work with coffeescript, sass and compass.
I would like to start a project with all these and not with pure js and css as the default setup does.
Is it possible to do it?
Yes it is possible but right now there is a bit of overhead required to get setup.
Have a look at https://github.com/gruntjs/grunt-contrib-coffee for info about converting coffescript to js using grunt. mean.io uses a lot of the grunt tools.
I would also recommend emailing a colleage of mine lior#linnovate.net. He has recently been building a sass package using the mean package system.
To see currently available packages have a look at http://www.mean.io/#!/packages

How to find modules dependency & install it but without cpan/cpanm?

The problem is I don't have access to write $HOME directory. (I only have access to create new directory on $HOME/app-root/data/)
because cpan/cpanm need to create new directory $HOME/.cpan/ I don't have idea how to find all modules dependency by hand (one-by-one).
Do you guys know other method to install module (and find dependency) but without to create ~/.cpan/ directory ?
or maybe how to override ~/.cpan/ to ~/app-root/data/.cpan ?
P.S: Sorry my english is bad, english isn't my native language
Just (temporarily) change $HOME to a directory you do have write access to:
HOME=$HOME/app-root/data/ cpanm Module
[An answer to the literal question is useful to people trying to install on a machine without internet, so I'll answer it even though it's not the best solution for you.]
To find the dependencies, you can use http://deps.cpantesters.org/. For example, here's the dependency tree for a module of mine.
Just list modules you need in .openshift/cpan.txt
Openshift will install it automatically when you deploy