How to install/run a node module from Windows cmd - javascript

Very big 'node' noob here. Just trying to get the lay of the land. I've installed node and the npm package manager based the excellent instructions found here. I can verify I have everything (node-wise) installed okay - with a user variable set to PATH =C:\Users\Dude\AppData\Roaming\npm
Using npm I installed
npm install -g query-overpass
npm install -g geojsonio
And verified that both had .cmd files and stuff show up here:
C:\Users\Dude\AppData\Roaming\npm
then from the cmd I put in the example
echo '[out:json];node(57.7,11.9,57.8,12.0)[amenity=bar];out;' | query-overpass
and got
{ message: 'Request failed: HTTP 400', statusCode: 400 }
Is there something I am missing here regarding installing node modules and how to run them (in Windows)? Is a .js file calling the modules what is required?

What makes you think there is an issue with your node modules? The error message is very clearly an HTTP error message, indicating a problem with the query you're making. Your modules are installed fine.
I don't know what your modules do, but you should try different parameters and contact the person that wrote them to indicate that their example no longer works.

Related

I can't use an API on Javascript, Might be related to node.js and such

Okay so I'm new to Javascript, please keep that in mind, and I'm working from a directory in my home computer, like, the web is not hosted in a server or anything, I've never done that
I've been trying to work with a Google Translate API (https://github.com/matheuss/google-translate-api)
I literally just copied the first example, and the console log on my web said something like
Uncaught ReferenceError: require is not defined file:///C:/Users/User/Desktop/web/script.js:11
For context, here's the line
const translate = require('google-translate-api');
Besides that whenever I try and install the api using the given Command on the Github page, I get some errors
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\User\package.json'
also
$npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\User\package.json'
$npm WARN User No description
$npm WARN User No repository field.
$npm WARN User No README data
$npm WARN User No license field.
and
$found 6 vulnerabilities (2 high, 4 critical)
When dealing with it by using $npm audit all I get is
$npm ERR! code EAUDITNOPJSON
$npm ERR! audit No package.json found: Cannot audit a project without a package.json
json
$npm ERR! A complete log of this run can be found in:
$npm ERR! C:\Users\User\AppData\Roaming\npm-cache_logs\2020-07-09T16_40_06_962Z-debug.log
and the same goes for $npm audit fix
I've tried to follow the guidelines I found on Github, even downloading the files directly to my project's folder (again, I don't really know if that would be useful at all), and nothing worked. I have GitHub on my PC, Git, nodejs, npmjs etc. and nothing works.
I've also used $npm init as sugested below (which created a package.json file) and then installed the API, but the console log part where it says
Uncaught ReferenceError: require is not defined
file:///C:/Users/User/Desktop/web/script.js:11
still happens
I've read somewhere, however, that I should use something like browsify because the problem might be related to the fact that my web isn't hosted on a server (again, idk the technical words, but I'm trying to explain my situation as best as I can), but maybe I'm just making a really simple mistake.
Here's some code that I copied directly from the API's Github page
(textoEntrada is just some text I put inside the thing from an input text box)
translate(textoEntrada, {to: 'en'})
.then(res => {
console.l`enter code here`og(res.text);
console.log(res.from.language.iso);
}).catch(err => {
console.error(err);
});```
you firstly need to make sure that you initialized an npm package by execute this command on command line:
npm init -y
then you will be able to install any packages.
also don't forget to get a walk on the npm docs, it definitely will help you later.

Problem with the command "npm install fs"

I am not used to work with Linux, so maybe this is a silly question. In the lab that I am working on, I am asked to run the command "npm install fs" to read/write files.
But here is the error that i have and I don't know how to solve it, i couldn't find similar problems too.
PS: I am working on Ubuntu 17.10.
fs is a module that doesn't have to be installed. It comes part of node.js core so you only need to require it in your code.
Instead of running npm install fs --save, just add the following line in the file you're wanting to use it in:
const fs = require('fs');
Here are the docs: https://nodejs.dev/the-nodejs-fs-module
However, to address your question, the error message your receiving is likely due to the fact that:
You don't have a package.json in your project
You are not in the correct directory when running npm install ... and therefore it cannot find your package.json.
I believe your mistake is that you skipped the part where you initialize your npm repository (which generates your package.json).
To initialize an npm repo, do the following:
Navigate to your project root directory
Run npm init and follow the instructions if when prompted.

JavaScript Program Path Not Specified Error

I've been creating a JavaScript game for a project recently and have done it completely on the CodePen website. I now am trying to transfer it to WebStorm to turn it into a basic website. However when I try to run my code I get the following error:
I don't know how to fix it, I've looked everywhere and haven't been able to get some help. Any information would be appreciated.
Simple one, basically the error says, I don't know how to interpret this bit of code that you just gave me. You're missing local install of Node.js and NPM. Get the latest versions of these 2, and then go to File -> Settings -> Language&Frameworks -> Node.js and NPM and in the Node interpreter text box, point it to the path of where node.js was installed.
You're running this JavaScript file with Node.js that is probably not installed on your machine. It seems that you want to run and debug your app in the browser instead. For that you need to create a JavaScript run/debug configuration instead as described here: https://www.jetbrains.com/help/webstorm/debugging-javascript-in-chrome.html
On a linux machnie,
Install nodejs and npm
sudo apt-get install nodejs
sudo apt-get install npm
Get the nodejs installation folder
whereis nodejs
Should print something like:
/usr/bin/nodejs /usr/lib/nodejs /usr/include/nodejs /usr/share/nodejs /usr/share/man/man1/nodejs.1.gz
Go to:
Webstorm-> File -> Languages & Frameworks -> Node interpreter
Copy paste the installation folder to the text box.
Mac OS here. Solved the issue with:
$ brew install nodejs

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.

How to run node.js applications locally for development

I am new to node.js,today I joined in another team they are working with node.js,backbone.js,marionette.js and sqlserver.I have an idea about backbone,Marionette but I never work on node.js.They asked me to clone the git repository,As per their suggestion I installed node.js.
After cloning the repository,I got the files just in the following way.
I opened node_modules folder,It has nearly 10 sub-folders are there.
node-sqlserver doesn't have any files inside.might be because of that I am getting the following error while server running time.
I ran the server with the following command
node server.js local
getting the following error
I don't know,why I am getting.can anyone help me.
Thanks.
You need to install all the dependent modules through npm install, In your case, you need to install node-sqlserver.
npm install node-sqlserver
Generally your source code will be having a package.json. This file specifies all the
dependent modules required to run the application, but here this file is missing.

Categories