Doubt Command Require

Asked

Viewed 45 times

0

I’m trying to use the require command but this giving error, I’m trying to use in the following code:

var Parser = require('C:/Users/gabri/OneDrive/Área de Trabalho/faculdade/Supervisorio_P1/polo/teste/Scripts/node_modules/jsonparse/jsonparse.js');
var request = new XMLHttpRequest();

You’re making a mistake in the require, someone knows why?

  • Have you ever tried to put the path from the folder that is the file you are modifying? Because you are using the full path. It could be something like this: var Parser = require('.. /jsonparse.js');

1 answer

1

When you are going to make a require of some module in Node.js, you do not pass where it is but the name of the module, in your case the json-parser

Example

var Parser = require('json-parser');

Node.js already searches inside the folder node_modules the module with that name and already defines in the variable that module, in its variable case Parser

Ready now you can already use the functions of the module json-parser calling the variable Parser

Example

Parser.NomeDaFuncao();

If you have any more questions about this package visit the website clicking here

Browser other questions tagged

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