import it, as shown in the following code:
The Code is as follows:
Var module = require ('module _ name ')
The above code imports a module named module_name, which may be a core module or a module installed with NPM. The require function returns an object containing all the public APIs of the module. The returned object may be any JavaScript value, a function, or an object that contains a series of attributes (functions, arrays, or any JavaScript Object.
Export Module
The CommonJS module syst
import it, as shown in the following code:
The Code is as follows:
Var module = require ('module _ name ')
The above code imports a module named module_name, which may be a core module or a module installed with NPM. The require function returns an object containing all the public APIs of the module. The returned object may be any JavaScript value, a function, or an object that contains a series of attributes (functions, arrays, or any JavaScript Object.
Export Module
The CommonJS module syst
to the current context, such as var math = require ('Math ');2). module definition: Use the exports object to export methods or variables of the current module. A module object exists in the module. exports is actually a module attribute. In Node, a file is a module, and the "global variables" in the module are invisible to the outside. Only the attributes mounted on exports are public, such as exports. add = function () {}; exports.
written in C/C ++ and loaded using the dlopen () method.3). json file: Read the file synchronously through the fs module and parse the returned results using JSON. parse ().4) Other extension files: All files are loaded as. js files.
We know that each module file contains the require, exports, and module variables by default, and even in the Node API documentation, we know that each module has two variable
Install node. js under Ubuntusudo Install Make sudo add-apt-repository ppa:chris-lea/node. jssudo apt-get updatesudo Install NodejsInstalling node. js on CubieboardMy Cubieboard 2 installed is Linaro 12.11, using Ubuntu installation method does not correctly install
Node module, the identifier does not contain the file extension. Node will be added in the order of. js,. node, and. json. During the attempt, the fs module needs to be called to synchronously block and determine whether the file exists. Because the Node is single-threaded,
Module stability: 5-lockednode has a simple module loading mechanism. in node, files and modules are one-to-one. for example, foo. javascript loads the circle in the same folder. js module. foo. js content: [javascript] lt; SPANstyle quot; FONT -...
Module)
Stability: 5-locked
Node has a simple module loading mechani
You have two options to implement the installation of Nodejs on Cubieboard, download other people have compiled the Nodejs binary package for Cubieboard, or download the source code on their own to compile on the Cubieboard.Using a compiled binary packageDownload node. js for ARM architecture Here, if you can't find the resources in the Cubieboard community, you can find similar resources in the Raspberrypi
Module)
Stability: 5-locked
Node has a simple module loading mechanism. The files and modules in node correspond one to one. For example, foo. js loads the circle. js module in the same folder.
Foo. js content:
[Javascript]Console. log ('the area of a circle of radius 4 is'+
This article mainly introduces the simple getting started course of Nodejs (1): module mechanism. This article describes the basic knowledge of the module, module loading, and Package content, if you need it, you can refer to the JavaScript specification (ECMAScript) without defining a complete set of standard libraries that can be applied to most programs. CommonJS provides a set of JavaScript standard library specifications. Node implements the Comm
));Contents of circle. js:
Var PI = Math. PI;
Exports. area = function (r ){Return PI * r;};
Exports. circumference = function (r ){Return 2 * PI * r;};Module circle. js exports the area () and circumference () functions so that
the module's location by relative or absolute path, for example:var mymodule = require ('./mymodule.js ');The module contains a lot of functional code snippets, the code in the module is mostly private, meaning that the function methods and variables defined in the module can only be called in the same module. Of course, some methods and variables can be exposed to the module, this time you can use export is the object to implement, such as the following code:var
This article mainly introduces Node. js module loading details. This article describes how to load core modules, file modules, directory modules, and file Loading modules, for more information, see JavaScript, one of the most frequently used programming languages in the world. It is a common language in the Web world and used by all browsers. JavaScript was born in the era of Netscape, and its core content
interface, such as Web server or database.
JavaScript does not have a package management system. Dependencies cannot be loaded and installed automatically.
Hence the advent of the COMMONJS (http://www.commonjs.org) specification, which aims to build a JavaScript ecosystem that includes Web servers, desktops, command-line tools, and browsers. COMMONJS has developed some specifications to address these issues, and node.
Transferred from: http://segmentfault.com/a/1190000000728401Modulenode. JS provides exports and require two objects, which exports are interfaces exposed by the module, that are require used to obtain an interface for a module externally, that is, the object of the acquired module exports .Next we'll create hello.js the file with the following code:function() { console.log(‘Hello World‘);}In the example above, hello.js the exports object is world use
Module. exports in Node. jsWhen writing node. js code, we often need to write modules by ourselves ). At the same time, you also need to write the module interface at the end of the module to declare what content this module exposes to the outside world. In fact, the module interfaces of node.
In php,c++, there is the concept of namespaces, namespaces are mainly used to solve the introduction of file existence function, class, variable name of the problem, in node. js, there is no namespace so complex concept, in node, there is the concept of module, that is, the functional code is put together. It is then introduced and used in this document. This doe
When writing the node. JS Code, we often need to write our own module. At the same time, it is necessary to write the module interface at the end of the module, declaring what the module exposes externally. In fact,node. JS has a number of different syntax interfaces. Here the author makes a brief summary of this.
node. JS provides a simple modular system to allow node. js files to be called each other. Modules are a basic part of the node. JS application, and the files and modules are one by one corresponding. In other words, a
This article mainly introduces the method for exporting Node. js excel. The example analyzes the detailed steps and related skills for exporting node. js excel. For more information, see the example in this article. Share it with you for your reference. The details are as follows:
Nodejs generates and downloads excel
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.