Installing a library using npm - javascript

I've a question regarding how to use a js library that is installed via npm. I have a simple webapp that compiles using gulp, so I installed the library using --save to populate my package.json but now what? should I add it as a gulp task too? I am not clear about all this process. Thanks

Almost always, libraries installed using npm i --save are ready to be require()d right out of the box.
The gulp tasks you might see on a library's source in GitHub is for developers of that library to build and test the library locally.
npm has utilities for running all of the build tools automatically before the library is published (with npm publish) and while the consumer's (yours) npm install is running.

Related

Is there a way to download all dependencies in a package-lock.json/yarn.lock file without installing them?

I am trying to stage dependencies from the NPM registry in a Nexus NPM proxy repository for any arbitrary JavaScript project. I can perform an npm install or yarn install which will cause all the dependencies to be staged, but I'd like to avoid that. The main reason is I want to avoid needing the necessary C/C++ libraries installed to compile the dependencies that are NodeJS C/C++ add-ons.
The only solution I can think of is by parsing the package-lock.json/yarn.lock file and running npm pack <dependency> for each dependency, which will cause npm to fetch the needed dependency and copy the tarball of the dependency to the current directory. I could then delete each downloaded tarball.
Is there a more elegant solution for either npm or yarn?
If you run npm install --ignore-scripts then the install scripts will be ignored and so any C/C++ files won't be built anymore.

What is difference between npm install and meteor npm install

I am working on Meteor and want to know that what is the difference between
npm install and meteor npm install.
Thanks
According to Meteor Development Group's comments in the official forum, the difference is as follows;
meteor npm calls the bundled npm version, so it doesn’t require npm to be installed globally, That is just a convenience however, so if you do have npm installed using that will work perfectly fine. That being said, it is a good practice to get into always using meteor npm, as that way you can make sure you’re using the same npm version that has been tested with your current version of Meteor.
When using meteor npm you can make sure that you are using the same npm version that has been tested with your current Meteor's version.
When using npm install it just uses the global npm on your machine. So i'd advise to use meteor npm
This may help you to understand difference between npm install and meteor npm install
The former is installing npm packages, which will be listed in packages.json and located in the node modules directory and need to be imported into your code.
The latter is using atmosphere packages which will be listed under .meteor/packages and will be included in your build (no need to import).

How do I run a program that I git cloned?

I'm new to git. I just git cloned this library and am trying to run the code in this folder. I know that it uses Javascript so I tried using npm start but it gave me a npm ERR! missing script: start error. How do I run it?
You should use the Getting Started guide on their docs. You are meant to install the package via npm and not cloning it using git. You would only clone the repo if you intend on modifying their code.
2.1 How to Install
This charts library is intended to be installed with npm and the built into your project with a tool like Webpack. It expects React to be present, as well as our TimeSeries abstraction library, pond.js. More on this below.
To install:
npm install react-timeseries-charts pondjs --save

How do I use two versions of Electron on the same machine

When I first started to learn Election the book I was using recommended that it be installed using npm install -g electron. Now I read on the npm website that npm install electron --save-dev is the preferred way to install it.
So I created a new project directory and ran npm init then ran
npm install electron --save-dev. According to package.json Electron 1.7.5 was installed, but when I type electron in the project directory it reports version 1.6.10 which is the version that was installed with the -g option.
Is there a way to get my new project to use 1.7.5? I have already completed a small project using version 1.6.10 and don't want to do anything that would keep it from running.
Thanks, Jim
You can run the local version of electron out of the node_modules/.bin directly -- most likely it will be called node_modules/.bin/electron.
You can use npm or gulp (or even a shellscript/batch file) to run the app for you.

Using Node.js with CouchCMS

I would like to use the features of Grunt and Gulp (preprocessing, compressing, watching etc.), but I don't want to abandon traditional PHP. I use CouchCMS which requires traditional PHP.
Can I use both CouchCMS with Grunt or Gulp? If not, why is that so, and is there any viable alternative?
Thanks
You can just create Gruntfile.js in your core folder with configs and run it from same folder where your project located by grunt <command>. To install grunt as application, you need to install node and npm and then by using npm(Node Packaged Modules) you can install grunt/gulp via npm install -g grunt or npm install -g gulp. By adding -g property, you force installing packages inside your execution folder bin and you can use those packages as standalone console application.
If you want a task runner for PHP you can use robo.li instead of Grunt, since grunt is meant for js.

Categories