2 ms·
> combination of good practises Other languages have that as well, although probably not the same good practices. > commonjs lexical scoped module system Fas
by erikb 10y ago
> combination of good practises
Other languages have that as well, although probably not the same good practices.
> commonjs lexical scoped module system
Fast googling of commonjs results in it being some kind of standard library? Not really sure what this is. Can you explain more in depth?
- z3t4 10y agoNode uses JavaScript witch is a simple scripting language that is event based, asynchronous, and thread safe. In JavaScript there are values: 42, "hello", true. And objects: [list], {object}, function. And if statements ... While more stuff exists there is a consensus in the JavaScript community that they should be avoided, so you rarely see the bad parts. Then there are only a handfull of built in JavaScript functions. And there is no concept of stack, pointers or types. How the data is represented in binary vary and is very optimized. A node script is usually a bunch of functions that are called by IO events, like a IP socket connection or callbacks from data streams, like when a buffer is filled. Node has no standard library, just a bunch of built in modules, that are required like any other module. And Node does NOT support imports, includes, or global variables, instead you require Modules. And since modules are lexically/function/block scoped, they can only be called from within the function from where you required them. You never have to look elsewhere to see where a variable is declared, or search for places where it's used, like in many other programming languages. Here's an example how a NodeJS script can look like: var socket = require("socket"); socket.onConnection = function socketConnection(client) { client.onData = function dataReceived(message) { var sms = require("sms"); sms.send(message); client.send("SMS message sent"); } } Besides lexical scoped modules in the example above there is also a "closure" of client in dataReceived from when socketConnection was called.