Can i use yarn instead of npm? - node.js

I'm super new to node and coding in general so please forgive me. I am trying to use weld scraping service, but I am using npm. To run, it says to use a yarn command: yarn dev # development . Is there a way I can run the same command with npm? I tried npm install dev # development, but it threw an error for the #. I tried downloading the contents of the repository first and then running, and got the same result. I tried researching what # means in yarn, or in terminal, and the only thing I found is in a shell script it shows that you are the superuser?

...Yarn can consume the same package.json format as npm, and can install any package from the npm registry.
https://classic.yarnpkg.com/en/docs/migrating-from-npm/

First of all Yarn is a package manager created by Facebook as an alternative to npm. It looks like the package you are trying to install can not be installed with npm. "npm install dev # development" will not work because it is not the format used by npm when you are trying to install some package. If the objective is to scrape a web site I recommend you to use some other popular npm packages as axios cheerio. You can use "npm install axios cheerio" to use them.

Related

Why does "npm install" require Node.js preinstalled in the system?

I've recently started Tailwind CSS where I've to install Tailwind into my system, not knowing the fact that my system has to contain Node.js preinstalled in my system I proceeded to paste npm install -D tailwindcss postcss autoprefixer in the terminal but it threw so many errors. After some research, I found about Node.js. Though my problem is solved I want to know why it happened.
The reason it needs nodejs is as simple as, you need to have a nodejs to have/use the npm. Nothing more than that.
Diving into what you are doing here: By running npm install tailwind, you are installing a node package called tailwind with a package management tool called npm. Nodejs is the javascript environment that gonna execute it later when you use it
Think of the the relationshipi between pip and python. When you try to install a python package, you use a python package manager called pip. What you are doing here is, you need tailwind css module, now you need node package manager (NPM) to have it download and work with nodejs.
Some furthur reading:
what is npm:
https://www.w3schools.com/whatis/whatis_npm.asp
Where your tailwind package come from:
https://docs.npmjs.com/about-npm

nodejs conflicting with vue native router

nodejs version 14.17.5
vue native version 0.3.0
I am developing an application that requires navigation in APP.
When i give command "npm run start" the application successfully runs.
Package.json dependencies installed:
enter image description here
For navigation when i run command "npm install view-native-router" it shows the error message as below:
enter image description here
Does anybody have the idea what could possibly have gone wrong? Is it a compatibility issue ?
It seems this is not the first time we have a peer dependency problem here and the last issue was marked as solved.
https://github.com/GeekyAnts/vue-native-router/issues/45
Since you have a higher version of vue-native-core in local, try add --legacy-peer-deps to npm install to see if works.
Though --force or --legacy-peer-deps may work for some but not everyone.
My solution is to start using yarn! Install it by the following:
$ npm i -g yarn
After its installed, its advised that you delete the project and redo the vue-native-cli init command so it can use yarn from there, but you can also just directly use the following command without deleting the project:
$ yarn install vue-native-scripts

Create-react-app not working - packages looking for funding

I installed node, then I ran npm install create-react-app, then ran npx create-react-app hello-world.
The last command did not go through because of some package funding, whatever that means.
How do I fix this?
I am using windows. Here is how my command prompt looks like:
When you do "npm install create-react-app" you're installing in the current folder a CLI to ease up creating a React template for your projects. Doing "npx create-react-app hello-world" is redundant as you've already downloaded the create-react-app module, if you do not wish to save the CLI software and only create the template then it's a better approach.
Using the "-g" flag will allow you to use the CLI globally to create React projects on your computer ("npm install -g create-react-app" this might require certain permissions) instead of only the specific folder you're on.
Once you're done you must use the command "create-react-app 'your_project_name'" to use create-react-app to create your project. More information here https://reactjs.org/docs/create-a-new-react-app.html#create-react-app, to start the project just head inside the created folder and do "npm start".
Packages looking for funding is exactly what it says, the developers of these modules are looking for funding.
Uninstalling x64 version of node and install x34 version solved my same issue.

'npm install --only=dev' deletes existing packages

While working on a node project, I am having trouble separating installation of application and test dependencies using npm. I am using node version 8.1.2 and npm version 5.0.3.
To elaborate, I am using docker to create production and test images for my node application with the idea that the production image will have only the application dependencies installed (e.g. aws-sdk, xml-builder). I am doing this by running npm install -q --only=prod in the production docker image.
The test image extends the production image and installs the test dependencies (e.g. chai, mocha) on top of it. This is achieved by running npm install -q --only=dev command in the test docker image. The purpose of this exercise is to create a clean production image that doesn't have unnecessary packages.
But when I execute the latter npm command (npm install -q --only=dev) it removes the packages installed by the first install. I'm doing the same thing in another project that uses an older version of npm and node and it works fine.
Did something change in the latest version of npm? If so is there another prescribed way of achieving the same effect?
It's not because of the new version of Node.js, but because of the new version of npm that is bundled together (version 5).
In your case you could do one of these:
Execute first npm install --only=prod in your production image, and then just npm install in your test image.
Deleting package-lock.json after the first npm install.
Using the option --no-package-lock in each npm install.
The new npm version uses a new file called package-lock.js, the one producing this behaviour, more info here.
EDIT:
I just found out this is an issue with npm, it seems it will be fixed in the next release. At the moment the workarounds I wrote above should work.

Create a script that fetch dependencies, install + start browser

I have an application on with a node server and I would like to do something like :
npm start
and node dependencies will install and bower dependencies will install, after that a browser window could open.
Can I do this without gulp/grunt? If I need gulp/grunt I don't mind.
You must issue
npm install
before you call the command npm start, because when the scripts start to run they need the dependencies already installed.
And to start a server and open it in a browser, it's well explained here:
How to Use npm as a Build Tool
(Look at the last example of the article)

Resources