Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require syntax in node

Is:

// Load the net module to create a tcp server.
var net = require('net');

using require.js?

like image 812
Cen Avatar asked May 09 '13 01:05

Cen


People also ask

What is require () in NodeJS?

2011-08-26. Node.js follows the CommonJS module system, and the builtin require function is the easiest way to include modules that exist in separate files. The basic functionality of require is that it reads a JavaScript file, executes the file, and then proceeds to return the exports object.

Does Node still use require?

Node. js follows the commonJS module system, and it require to include modules that exist in separate files and for that purpose it has methods like “require” and “ES6 import and export” are available in node.

What can I use instead of require in NodeJS?

Use Import Instead of Require in Node App.

Should I use require or import?

The major difference between require and import , is that require will automatically scan node_modules to find modules, but import , which comes from ES6, won't. Most people use babel to compile import and export , which makes import act the same as require .


1 Answers

require is a globally-scoped function in Node.

like image 62
Joe Avatar answered Sep 26 '22 22:09

Joe