Cant resolve fs, net, tls after mysql installation - javascript

I have react-boilerplate application. I want to start using database so I installed:
npm install mysql
npm install mysqljs/mysql
As shown in mysql webpage: https://www.npmjs.com/package/mysql
Now I get errors when I go to localhost in a browser:
Can't resolve 'fs' in '....node_modules\mysql\lib\protocol\sequences'
Can't resolve 'net' in '....node_modules\mysql\lib'
Can't resolve 'tls' in '....node_modules\mysql\lib'
I am using redux-saga combination.
I figured out that I get the error when I write:
const mysql = require('mysql');
in saga.js file
How can I fix these errors?

You can't use a MySQL client library within a browser app.
The errors you're seeing is the client library attempting to require() Node.js standard libraries for file system, network and encryption (TLS) access, which don't exist in the browser.

Related

deploying js with python and spacy lib

I have never setup things this way, I got it running locally but have no clue how I should have do it when I deploy it into an ec2 server
I have a node app running already in ec2 server but recently I have added spaCy into one of my api.
The basic logic is calling the api which runs node and part of the js script uses spawn to process the proc.py file and do some calculation with outputs.
I have tried the following below to setup on my server but of course it failed when calling the api
my original node app is in /var/www/myApp
I used sudo apt install virtualenv then inside my /var/www/myApp I ran the command virtualenv venv which creates the virtual environment...
I did a source venv/bin/activate to get into the virtual environment
Then I started running the commands to install spacy mentioned in the spacy documentation https://github.com/explosion/spaCy
used this command to install pip install -U spacy and python -m spacy download en
Then I ran python -m spacy validate to see if spacy is installed which I got
Installed models (spaCy v2.0.11)
/var/www/myApp/venv/local/lib/python2.7/site-packages/spacy
TYPE NAME MODEL VERSION
package en-core-web-sm en_core_web_sm 2.0.0 ✔
link en en_core_web_sm 2.0.0 ✔
which I believe this means the installation is a success.
But after this, I am not sure what I should do to continue.
I tried running my api but getting this as an error message "err": "Traceback (most recent call last):\n"
I would believe the spacy module is not being called that's why I am getting this error but I am not sure what I should do to get this working.
Would really appreciate for any help, thanks in advance for any advices.
EDIT:
my proc.py code is below
if __name__ == '__main__':
import sys
import json
import spacy
nlp = spacy.load('en')
text = sys.argv[1]
doc = nlp(text)
all_noun_tokens = [ token.lemma_ for token in doc
if (token.pos_ == 'PROPN'
or token.pos_ == 'NOUN'
or token.tag_ == 'NN'
or token.tag_ == 'NNP') ]
print(json.dumps(all_noun_tokens))
P.S. I am wondering if there's any config that I need to do in order for my app to find where the virtuanenv is so it can detect the spacy module?

How to use sql-injection package in Node.js application?

I want to prevent my app for SQL-Injection attack in Node.js,for that i am using sql-inection package of NPM.
My app.js File
var app = express();
var sqlinjection = require('sql-injection');
app.use(sqlinjection);
With this configuration i am directly sending request to server.
But with each request to the server the api does not send any response and gives no error or Warning.
I am using this Npm package sql injection npm js
Please guide me to how to use sql-injection in node.js and express.js project.
Thanks.
Please include following lines in your app.js file
app.use('/wordcloud',wordcloud);
app.use('/profanityfilter',profanityfilter);
app.use('/api/notification',notification);
app.use('/api/badge',badgecount);
app.use('/api/csrf',csrfRoute);
app.use(sqlinjection);
After requiring the npm package you must use this sql-injection package at the end of all your router.
and it will work fine.

Illegal token in meteor/node module => cookies

I was attempting to follow along with g00glen00b's meteor/twitter walkthrough (http://g00glen00b.be/meteor-twitter-streaming/) when i got this persistent error. any help or hints would be much obliged.
things i tried
uninstall/reinstall npm
uninstall/reinstall twitter package
uninstall/reinstall cookies
searching for hidden characters
my deployed app
(htp://dbcmarch.meteor.com)
meteor error
=> Errors prevented startup:
While building the application:
node_modules/twitter/node_modules/cookies/test/express.js:1:15: Unexpected token ILLEGAL
node_modules/twitter/node_modules/cookies/test/http.js:1:15: Unexpected token ILLEGAL
express.js
#!/usr/bin/env node
var assert = require("assert"),
express = require("express"),
http.js
#!/usr/bin/env node
var assert = require("assert"),
http = require("http"),
meteor includes npm, and its perfectly acceptable to run 'mrt add npm' however npm should not be used to install its packages (e.g. npm install twitter) into a meteor project. you can require them via a packages.json file.
in order to avoid the illegal token error and get the server up running, i deleted the primary node_module dir in my project folder.
check the meteor google group for advice!

MongoDB's Node.js Driver installation fails

I have nodejs and mongoDB installed on 32bit winXP veteran. And I am trying to link them.
In the mongoDB docs its stated that the easiest way is by this command:
npm install mongodb
Unfortunately it throws the following exception:
"Failed to replace env in config: ${APPDATA}"
I tried to point the NODE_PATH variable to the "npm\node_modules" folder but this does not solve my problem.
What additional configuration am I missing?
In the end just ran the cmd not as Administrator but simply from my account and the command("npm install mongodb") worked as expected.
After that I uninstalled it since this was kind of weird. And again tried as Administrator and it failed again. And again succeeded with my account. So I left it be.

Can't connect to local mongoDB install

After downloading, extracting, creating the data/db folder and cd-ing into where I extracted mongoDB, I tried running this command, as directed by the official mongoDB install instructions: .bin/mongo/ but I keep getting this error:
Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
I can't find a concise explanation on the internet, though it seems to be a common problem, and the mongoDB docs aren't clear either. Can anyone help me out?
Start the server before trying to connect with a client:
mongod
Or if you want to specifically point it at a db location, and log to a log file:
mongod --logpath /data/log/mongo.log --dbpath /data/db
Or something of this nature. This command will run the server in a foreground process. You can use --fork to daemonize it.

Categories