LoopBack installation through npm not working on Windows [duplicate] - javascript

When I run npm install -g <package> it installs the packages in my user/AppData/Roaming/npm/npm_modules/ folder. This sub-folder is not in my PATH so if I try to run the package without explicitly calling the entire path the call fails with a '<package>' is not recognized as an internal or external command, operable program or batch file.
What can I do to fix this?
Thanks

I'm using win8.1 and I found that the nodejs installer didn't add the path to global node modules to the system PATH. Just add %AppData%\npm; to the user variable(since %AppData% dir is depending on user) PATH to fix it.
You will need to log out then log back in for the change to your PATH variable to take effect.
SET PATH=%AppData%\npm;%PATH%

You have to run this line SET PATH=pathtonodejs;%PATH% (where pathtonodejs is where you installed nodejs) once the installation for nodejs is complete and it should work.

It turned the problem was a change in behavior of the module I was using.
I'd been following old tutorials for using Express.js. The old tutorials assumed Express would be in my path after installing it globally, but as of Express v4.0 there's a separate Express module you have to install in order to get it in your path

Related

How to imitate my library is a node module without uploading to the NPM?

If I'm developing a library which work is based a lot around of current working directory and the filesystem generally, a lot of paths resolution, and I want to see how it will behave when will be installed as a node module, I don't want to get unexpected results when I'll upload it to the npm. How do I test my library behavior pretending it's a node module? Is placing its folder in node_modules enough?
Make a local package and install it everywhere:
$ npm pack
it will generate a zipped file, so you can copy somewhere and install it.
// another project
$ npm install /path/to/pack
Resources:
npm pack,
Add local package
Absolutely you can use npm link too. link

sockets.io.js module not found

I am currently working on a website project using javascript. I am unable to call the socket.io module, which I installed using npm install socket.io.
I tried to use it in the HTML script:
<script src="/socket.io/socket.io.js"></script>
But I got an error, apparently because the module is not found.
I didn't find any other way to install it on the internet. Does anyone know a way to avoid this problem?
When you do npm install socket.io, the socked.io library is installed to a special directory called node_modules.
In your HTML file, you are trying to load the library from a path that expects it to be located in a subdirectory called socket.io in the public documents directory of your server.
You have three options:
copy the socket.io library to a directory where your server can serve it and the browser can find it
adjust the path in your script tag to point to node_modules/socket.io
load socket.io from a CDN, for example:
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
I would recommend the third option.
You can install it globally using -g parameter:
npm install -g socket.io
If you don't want to do the above then you need to run the project using local node_modules dependencies. To do that:
Add the following alias in ~/.bashrc alias npm-exec='PATH=$(npm bin):$PATH'
Run all npm commands by prefixing npm-exec to use local node modules
Example: npm-exec npm build

Cannot find module 'crawler'

After installing node-crawler in Node.js (not in the default directory) via the npm command, I tried to run the code in the "Usage" section but an error occurs when executing var Crawler = require("crawler"); and the VisualStudio Code debug console says Cannot find module 'crawler'.
Does it happen because I installed crawler in a custom location? How can I fix this?
npm install will install a package locally. (--save to have package appear in your dependencies.)
To have access to it from everywhere, you need to install it globally, using npm install -g
Maybe I found the solution. I replaced "crawler" in var Crawler = require("crawler"); with the path that points to the crawler.js file in the lib folder in node-modules, and now the code works. Maybe it happened because I installed crawler in a custom location and so VisualStudio couldn't find "crawler".

Node.js - Globally installed module showing 'MODULE_NOT_FOUND'

I am using Node.js for a project. I installed WebdriverIO globally using
npm install -g webdriverio
In one of my files, I have:
file.js
var webdriverio = require('webdriverio');
When this file gets loaded, I get an error in the console that says:
Message:
Cannot find module 'webdriverio'
Details:
code: MODULE_NOT_FOUND
If I comment out the line var webdriverio = ..., my code runs fine.
Considering I've installed webdriverio globally, I do not understand why I'm getting this problem.
When you install globally, you should then go to the root of your app and call:
npm link webdriverio
P.S. no need to call npm install, since you will end up having two separate installations of this module, one in global and another in your local node_modules folder
Node.js require looks into the local node_modules folder.
Check this link to learn how to load modules from the global modules folder:
https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
If the NODE_PATH environment variable is set to a colon-delimited list
of absolute paths, then node will search those paths for modules if
they are not found elsewhere. (Note: On Windows, NODE_PATH is
delimited by semicolons instead of colons.)
You need it locally for your app, run npm install webdriverio in the root directory of your app.
Node looks for modules in the innode_modules folders only (starting with current folder and then looking in the folder above). In order to make it work, you have to install this package locally as well.
npm install webdriverio
You can use the full global path:
const wdio = require('/usr/local/lib/node_modules/webdriverio');

error installing/running Meteor with MySQL

I have installed Meteorite on my mac, and am trying to run the test program provided as a mysql project. When I use the command 'mrt', I get:
Stand back while Meteorite does its thing
Done installing smart packages
Ok, everything's ready. Here comes Meteor!
[[[[[ /Users/lfrey/Desktop/Thesis/test-meteor-sql ]]]]]
=> Errors prevented startup:
While building the application:
node_modules/meteor/app/lib/unsupported.html:1: Can't set DOCTYPE here. (Meteor sets for you)
node_modules/meteor/app/meteor/meteor.js:1:15: Unexpected token ILLEGAL
=> Your application has errors. Waiting for file change.
I have tried re-installing nom, meteor, meteorite, and mysql in various combinations and have not been able to eliminate the error. If I remove the command, then I get an error about invalid HTML syntax.
Your app might not be created properly. You have a node_modules directory in your application which you might have added with npm install.
Meteor does not install modules with npm install manually, it doesn't work because it parses files in the node_moules directory as part of your meteor app (in the wrong way - not as an npm module).
You have to make sure the package you use uses Npm.depends in your package's package.js. The standard Meteor-SQL package already does this for you so you don't have to worry about it.
Which SQL package did you use? As far as I can see none of them install anything with npm install nor do they have instructions to.
The simple fix to get your app working is to remove the modules you installed by deleting the node_modules directory in your app.

Categories