Trying to use node.js, keep getting errors - javascript

I installed node.js because I needed a way for storing my javascript variables into a mysql database (I use phpmyadmin).
I'm getting this error and I just don't now what to do with it:
C:\Users\Robin> npm install mysql
C:\Users\Robin
`-- mysql#2.13.0
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Robin\package.json'
npm WARN Robin No description
npm WARN Robin No repository field.
npm WARN Robin No README data
npm WARN Robin No license field.
I also typed another command (can't remember which one) and it gave me a list of what looks like usernames and email-accounts.
I have no idea which steps I need to take for succesfully installing node.js and make it work. I checked youtube video's and stuff but there like worthless.
So my question from scrath is: I installed node.js, how to make it work?
Kind regards from the Netherlands

Well, I may get your problem . Then i searched and found some valuable steps for you from the internet .
Create a new project: mkdir mysql-test && cd mysql-test.
Create a package.json file: npm init -y.
Install the mysql module: npm install mysql.
Create an app.js file and copy in the snippet below (editing the placeholders as appropriate).
Run the file: node app.js. Observe a “Connected!” message
Here is the Url where i got these information :https://www.sitepoint.com/using-node-mysql-javascript-client/
Best of luck .

You need have package.json file.
Do first:
npm init
Then you will have package.json. Now you can do:
npm install package
Or
npm install package --save (for save dependencies in package.json)
EDIT:
Iam trying do npm intall in a void folder in my coputer:
diego.martin#csa-188:~/Proyectos/pruebas/prueba$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (prueba) Hello
Sorry, name can no longer contain capital letters.
name: (prueba) hello
version: (1.0.0)
description: None
entry point: (index.js)
test command:
git repository:
keywords:
author: Diego
license: (ISC)
About to write to /home/diego.martin/Proyectos/pruebas/prueba/package.json:
{
"name": "hello",
"version": "1.0.0",
"description": "None",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Diego",
"license": "ISC"
}
Is this ok? (yes) yes
Then i have packaje.json:
diego.martin#csa-188:~/Proyectos/pruebas/prueba$ ls -la
total 12
drwxrwxr-x 2 diego.martin diego.martin 4096 jul 5 13:30 .
drwxr-xr-x 11 diego.martin diego.martin 4096 jul 5 13:25 ..
-rw-rw-r-- 1 diego.martin diego.martin 210 jul 5 13:30 package.json
diego.martin#csa-188:~/Proyectos/pruebas/prueba$
Lastest:
diego.martin#csa-188:~/Proyectos/pruebas/prueba$ npm install mysql --save
hello#1.0.0 /home/diego.martin/Proyectos/pruebas/prueba
└─┬ mysql#2.13.0
├── bignumber.js#3.1.2
├─┬ readable-stream#1.1.14
│ ├── core-util-is#1.0.2
│ ├── inherits#2.0.3
│ ├── isarray#0.0.1
│ └── string_decoder#0.10.31
└── sqlstring#2.2.0
npm WARN hello#1.0.0 No repository field.
diego.martin#csa-188:~/Proyectos/pruebas/prueba$

Related

npm reinstalls package.json and package-lock.json

my npm was working perfectly fine, today I wanted to install a package and I got a lot of npm ERR! messages.
Then I saw that npm was creating package.json, package-lock.json, and a node_modules folder in the directory I was installing the packages in.
Shouldn't these files and folders be in /bin/ somewhere?
Then after I reinstalled some packages npm ls works but after some time it outputs:
├── #babel/code-frame#7.18.6 extraneous
├── #babel/helper-validator-identifier#7.19.1 extraneous
├── #babel/highlight#7.18.6 extraneous
├── #jridgewell/gen-mapping#0.3.2 extraneous
├── #jridgewell/resolve-uri#3.1.0 extraneous
├── #jridgewell/set-array#1.1.2 extraneous
But not just these, there are hundreds.
I just uninstalled Node and npm and re-downloaded it again.
But now when I tried to install a package it created a node_modules folder, package.json and package-lock.json in my home directory.
These files and the folder is not supposed be there, right?
Thank you!

How to install npm using command prompt

npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) C:\Users\Acg-Tech\.config
I am getting this issue in command prompt. i have tried these commands sudo npm i -g npm, npm i -g npm-upgrade, by running in command prompt but it's not working for me. How to resolve this issue.can anyone please help me.
I'm assuming you don't have it installed. (Even in the case you have it, it can be easily updated by this method).
If you have a Mac, install Brew and if you are on Windows, Chocolatey and then follow their respective commands to install/update npm. They will mostly take care of all the necessities to install/download anything.
The command will be mostly:
brew/chocolatey install npm
if this a windows system you need to run cmd with administrator rights and try it.
Download and install nodejs
Also add nodejs path and npm in roaming folder paths to env variables

REACT - not working npm while installing it

Did all the command on command line
from installing the npm globally npm install -g create-react-app along with following codes:
npx create-react-app <myprojectname>
and also cleared the npm cache but it always get stuck on the line in the image showing the following error. Along with the error:
┌──────────────────────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) C:\Users\Smart Sites\.config │
└──────────────────────────────────────────────────────────────────
along with 65 packages are looking for funding
[1]: https://i.stack.imgur.com/KJVVp.png
Here is what i found form the getting started page of create react app.
If you've previously installed create-react-app globally via
npm install -g create-react-app,
we recommend you uninstall the package using
npm uninstall -g create-react-app
to ensure that npx always uses the latest version.
npx create-react-app my-app
cd my-app
npm start
But always ensure that you have an existing folder before using npx.

Create React App with Storybook creating webpack issue

So I have a large React app created and set up with Create React App. Recently we started using Storybook to work on and create components. Its been great. However, we keep getting this weird webpack issue when we try to run or build the app. Here is the console log out:
> react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.41.2"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
/Users/alexanderkaran/Documents/ClimateClever/cc_school_web/node_modules/webpack (version: 4.41.5)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /Users/alexanderkaran/Documents/ClimateClever/cc_school_web/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cc_school_web#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cc_school_web#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alexanderkaran/.npm/_logs/2020-01-23T05_20_16_003Z-debug.log
alexanderkaran#AlexandersMBP2 cc_school_web %
I know what your thinking you must have installed webpack, well I didn't. When I run:
npm ls webpack
I get this log out:
cc_school_web#0.1.0 /Users/alexanderkaran/Documents/ClimateClever/cc_school_web
├─┬ #storybook/react#5.3.8
│ ├─┬ #storybook/core#5.3.8
│ │ ├─┬ corejs-upgrade-webpack-plugin#2.2.0
│ │ │ └── webpack#4.41.5 deduped
│ │ └── webpack#4.41.5 deduped
│ └── webpack#4.41.5
└─┬ react-scripts#3.3.0
└── webpack#4.41.2
alexanderkaran#AlexandersMBP2 cc_school_web %
So the issue seems to be to do with storybook. If I uninstall all npm modules and remove storybook, then re-add both everything works again but eventually, it breaks.
Does anyone have a fix for this? Or am I missing something?
Looks like this an issue with the version of Webpack Create React App uses being a few steps behind the version Storybook uses sometimes.
There is no fix, but there are some workarounds.
You can find more info on the issue here:
https://github.com/storybookjs/storybook/issues/6505
One workaround is to add SKIP_PREFLIGHT_CHECK=true to a .env file in your project.
This can cause issue though.
Another workaround is to keep using a version of storybook and create react app that works with each other and doesn't cause these issues. So do not just upgrade storybook straight if it contains a Webpack version bump.

Travis CI Build Keeps Failing

I have a project that I am trying to incorporate Travis CI into for testing.
For the life of me, Travis CI keeps 'failing' when I do a Pull Request and/or push to my repos on GitHub.
Here is my .travis.yml file:
language: node_js
node_js:
- "node"
before_script:
-npm install -g webpack
-npm install -g mocha
-npm install -g chai
-npm start
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
Here is the message from Travis CI about the error:
Using worker: worker-linux-docker-f87d2e7f.prod.travis-ci.org:travis-linux-7
system_info
Build system information
Build language: node_js
Build group: stable
Build dist: precise
Build image provisioning date and time
Thu Feb 5 15:09:33 UTC 2015
Operating System Details
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
Linux Version
3.13.0-29-generic
Cookbooks Version
a68419e https://github.com/travis-ci/travis-cookbooks/tree/a68419e
GCC version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
LLVM version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Pre-installed Ruby versions
ruby-1.9.3-p551
Pre-installed Node.js versions
v0.10.36
Pre-installed Go versions
1.4.1
Redis version
redis-server 2.8.19
riak version
2.0.2
MongoDB version
MongoDB 2.4.12
CouchDB version
couchdb 1.6.1
Neo4j version
1.9.4
RabbitMQ Version
3.4.3
ElasticSearch version
1.4.0
Installed Sphinx versions
2.0.10
2.1.9
2.2.6
Default Sphinx version
2.2.6
Installed Firefox version
firefox 31.0esr
PhantomJS version
1.9.8
ant -version
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
Maven home: /usr/local/maven
Java version: 1.7.0_76, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.13.0-29-generic", arch: "amd64", family: "unix"
fix.CVE-2015-7547
$ export DEBIAN_FRONTEND=noninteractive
W: Size of file /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise-backports_multiverse_source_Sources.gz is not what the server reported 5886 5888
W: Size of file /var/lib/apt/lists/ppa.launchpad.net_ubuntugis_ppa_ubuntu_dists_precise_main_binary-amd64_Packages.gz is not what the server reported 36669 36677
W: Size of file /var/lib/apt/lists/ppa.launchpad.net_ubuntugis_ppa_ubuntu_dists_precise_main_binary-i386_Packages.gz is not what the server reported 36729 36733
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
libc-bin libc-dev-bin libc6-dev
Suggested packages:
glibc-doc
The following packages will be upgraded:
libc-bin libc-dev-bin libc6 libc6-dev
4 upgraded, 0 newly installed, 0 to remove and 221 not upgraded.
Need to get 8,844 kB of archives.
After this operation, 9,216 B disk space will be freed.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libc6-dev amd64 2.15-0ubuntu10.13 [2,943 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libc-dev-bin amd64 2.15-0ubuntu10.13 [84.7 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libc-bin amd64 2.15-0ubuntu10.13 [1,179 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libc6 amd64 2.15-0ubuntu10.13 [4,637 kB]
Fetched 8,844 kB in 0s (31.7 MB/s)
Preconfiguring packages ...
(Reading database ... 69991 files and directories currently installed.)
Preparing to replace libc6-dev 2.15-0ubuntu10.10 (using .../libc6-dev_2.15-0ubuntu10.13_amd64.deb) ...
Unpacking replacement libc6-dev ...
Preparing to replace libc-dev-bin 2.15-0ubuntu10.10 (using .../libc-dev-bin_2.15-0ubuntu10.13_amd64.deb) ...
Unpacking replacement libc-dev-bin ...
Preparing to replace libc-bin 2.15-0ubuntu10.10 (using .../libc-bin_2.15-0ubuntu10.13_amd64.deb) ...
Unpacking replacement libc-bin ...
Processing triggers for man-db ...
Setting up libc-bin (2.15-0ubuntu10.13) ...
(Reading database ... 69991 files and directories currently installed.)
Preparing to replace libc6 2.15-0ubuntu10.10 (using .../libc6_2.15-0ubuntu10.13_amd64.deb) ...
Unpacking replacement libc6 ...
Setting up libc6 (2.15-0ubuntu10.13) ...
Setting up libc-dev-bin (2.15-0ubuntu10.13) ...
Setting up libc6-dev (2.15-0ubuntu10.13) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
git.checkout
0.46s$ git clone --depth=50 --branch=master https://github.com/NAME/mood.ly.git NAME/mood.ly
Cloning into 'NAME/mood.ly'...
remote: Counting objects: 1183, done.
remote: Compressing objects: 100% (507/507), done.
remote: Total 1183 (delta 616), reused 1170 (delta 608), pack-reused 0
Receiving objects: 100% (1183/1183), 665.78 KiB | 0 bytes/s, done.
Resolving deltas: 100% (616/616), done.
Checking connectivity... done.
$ cd NAME/mood.ly
$ git checkout -qf 6bb7813f901f8d3cca359f8a9a1124df4dda86fe
This job is running on container-based infrastructure, which does not allow use of 'sudo', setuid and setguid executables.
If you require sudo, add 'sudo: required' to your .travis.yml
See https://docs.travis-ci.com/user/workers/container-based-infrastructure/ for details.
Updating nvm to v0.31.0
2.25s$ nvm install node
Downloading https://nodejs.org/dist/v6.1.0/node-v6.1.0-linux-x64.tar.xz...
######################################################################## 100.0%
Now using node v6.1.0 (npm v3.8.6)
$ node --version
v6.1.0
$ npm --version
3.8.6
$ nvm --version
0.31.0
install
47.43s$ npm install
npm WARN deprecated jade#0.26.3: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated graceful-fs#2.0.3: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs#^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN excluding symbolic link index.js -> lib/sass.js
npm WARN excluding symbolic link lib/index.js -> sass.js
mood.ly#1.0.0 /home/travis/build/NAME/mood.ly
├─┬ babel-cli#6.8.0
│ ├─┬ babel-polyfill#6.8.0
│ │ └── babel-regenerator-runtime#6.5.0
│ ├── babel-runtime#6.6.1
│ ├─┬ bin-version-check#2.1.0
│ │ ├─┬ bin-version#1.0.4
***A BUNCH OF OTHER DEPENDENCIES* (it goes over 30K characters so I had to redact it)**
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents#1.0.12
0.00s$ -npm install -g webpack -npm install -g mocha -npm install -g chai -npm run build-server - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start
/home/travis/build.sh: line 45: eval: -n: invalid option
eval: usage: eval [arg ...]
The command "-npm install -g webpack -npm install -g mocha -npm install -g chai -npm run build-server - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start" failed and exited with 2 during .
Your build has been stopped.
Would really appreciate some help/advice with this.
Thanks in advance.
The command "-npm install -g webpack -npm install -g mocha -npm install -g chai -npm run build-server - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start" failed and exited with 2 during .
This line should be the hint. Your npm has a dash before it (i.e: -npm). Add a space between the - and npm in your configuration.
before_script:
- npm install -g webpack
- npm install -g mocha
- npm install -g chai
- npm start
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

Categories