![]() ![]() How to Debugĭebugging domains is fairly straightforward. The "StaticServer" extension in "src/extensions/default/StaticServer" in the main Brackets repo is a more complicated example. In order to see the effect of changes you make in Node code, you can use Debug > Restart Node, or quit and restart Brackets entirely. However, the Node process isn't restarted when you reload Brackets. Usually, when you make a change to code in a Brackets extension, you can just reload Brackets to see the effect. emitEvent ( "simple", "log", ) Reloading the Node module emitEvent ( "simple", "log", scope ) _domainManager. Note that Brackets client code automatically registers as a listener for "log" events and forwards them to the client console, prefixed with "". On the client side, events can be listened for using the standard jQuery event system on instances of the NodeDomain class, by simply doing myDomain.on("someEvent", someHandler). Events are registered using the registerEvent command in the DomainManager, and emitted using the emitEvent. Your Node module can also asynchronously trigger events that can be listened to on the Brackets side. In either case ("synchronous" or asynchronous), your result or error will be sent back to your Brackets code via a resolved or rejected promise, as mentioned above. If you succeeded, pass null for err and pass your result as the second argument to the errback. If you encountered an error, then you should pass an error string back in err. When your processing is done, call the errback with two arguments, err and result. If you do this, then the final parameter to your command will be a Node-style "errback" function. If your command is asynchronous on the Node side, you can pass true for the fourth parameter ( isAsync) to registerCommand. When isAsync is set to false, it means that the command function is synchronous on the Node side, so when DomainManager calls it, it expects to get a return value from the command function directly, which it then sends (asynchronously) back to Brackets. This terminology is a bit confusing, because all communication between Brackets and Node is actually asynchronous. This example showed a command that was registered as "synchronous" ( isAsync was set to false in registerCommand). Check out the full source at More Tips for Creating Brackets Node Modules Asynchronous methods * // Log memory when extension is loaded logMemory ( ) Īs usual for Brackets extensions, you need to wrap this in AMD define() boiilerplate. ![]() ** * * Handler function for the simple.getMemory command. The first thing we need to do in this file is require the built-in libraries we'll be using: All of our Node code will live in a file called "node/SimpleDomain.js". We call Node modules that are accessible from Brackets "domains" (for historical reasons - note that this is a completely different usage from the term "domains" in Node itself). See ) Step 1: Implementing the Node module. (This is recommended practice in the Node community to ensure that all end users get the same bits. For distribution, the actual bits of any third-party modules should be bundled in to the zip - Brackets doesn't run npm install when installing an extension. gitignore) you can avoid checking third party code into your repo. By doing this (and adding "node/node_modules" to your. For development, Node modules can be installed through npm by putting a "package.json" file in the "node" directory and running npm install from inside that directory. Note on third-party modules: Convention recommends putting any third-party modules inside a "node_modules" directory that lives inside the "node" directory. By convention (but not by necessity), we put all Node code for the extension in a subfolder called 'node' inside the extension folder, including third-party Node modules. There's no special setup you have to do to make a Brackets extension call Node code, so you can create your extension as usual: create a folder for it and put in a "main.js" file that's the entry point to the Brackets-side code. The entire example is available as a Brackets extension at Step 0: Setting up the extension. This module allows client code to retrieve system memory usage information. Here we walk through how to implement a simple Node module that can be accessed from Brackets. Creating and Calling a Basic Brackets Node Module This document provides a quickstart guide for extension implementers on how to work with Node in Brackets, and also discusses the architecture of the Node integration in Brackets.įor more information on why we've integrated Node in the way we have, take a look at Research: Node.JS Integration. This is useful for adding functionality that requires deeper native OS access than provided by the Brackets shell - for example, running command-line processes. Brackets has a Node.js process integrated into the shell. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |