- 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);
});```