Install and use a library via NPM

Asked

Viewed 27 times

1

I’m beginning to understand the NPM now, I am very old school and I need to update myself.

I installed via NPM Jquery and some library to test (Inputmask). It seems that everything worked out, the folders were created inside the node_modules folder and my package.json file was like this:

{
  "name": "npm_tutorial",
  "version": "1.0.0",
  "description": "testando a instalacao via npm",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "teste"
  ],
  "author": "caiocafardo",
  "license": "ISC",
  "devDependencies": {
    "jquery": "^3.2.1"
  },
  "dependencies": {
    "inputmask": "^3.3.5"
  }
}

Now my question: how to use Jquery and Inputmask in HTML? I’ll have to call it like I always did?

<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>

Or is there some way to call more easily (all at once)? This index.js file became empty, it would be he who does the magic?

  • Are you using webpack, or Browserify? you have a server or are just testing in a static html file?

  • Locally, a static file. About webpack and Browserify, sorry, but I’m not using either....

  • In that case it works well as it is, assuming that the file .html is on the project’s core board. You got it up and running?

  • Yes, in the traditional way using script. But there is no advantage in using NPM. I can very well download the JS and call, right? I wanted to understand the advantage of using NPM.... because if I have to call it equal I always called, I see no advantage

  • 1

    Yes, exactly. Using npm is just a practical way to get the file into your project. But CDN is better if you work online, otherwise (offline) you really need the file locally.

  • But via CDN would use Github?

  • No, it uses Google directories for example: https://developers.google.com/speed/libraries/#jquery

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.