🚩 TODO
- .NET in-process using Edge.js.
- node-windows: Windows services, logging, and commands using Node.js.
- Create a DocumentDB database account
- Create a database
- Create a collection
- Add documents to the collection
- Navigate to the root project directory and install the
documentdb
package:npm install documentdb
- (Optional, but helpful for IntelliSense support in Visual Studio Code) Install the type definition file for DocumentDB with
tsd install documentdb
- Load the documentdb module:
var DocumentClient = require('documentdb').DocumentClient;
- Create a new
DocumentClient
object by specifying the endpoint URL and master key:var ddbClient = new DocumentClient(endpointUrl, {masterKey: masterKey});
💡 The endpoint URL and keys can be found in the Azure portal by navigating to your DocumentDB account
- Query all documents in a particular collection in a database
// note: the below code queries all documents in the collection with no
// predicate to filter any documents out
ddbClient.queryDatabases('SELECT * from d WHERE d.id = "database_name"')
.current(function (err, database) {
ddbClient.queryCollections(database._self, 'SELECT * FROM c WHERE c.id = "collection_name"')
.current(function (err, collection) {
var docQuery = 'SELECT * FROM collection c';
ddbClient.queryDocuments(collection._self, docQuery)
.toArray(function (err, documents) {
if (!err) {
console.log('found ' + documents.length + ' documents...');
for (var i = 0; i < documents.length; i++) {
console.log(documents[i]);
}
}
});
});
});
- tedious - TDS client written in JavaScript, no binary dependencies
- mssql - Friendly interface wrapper around SQL clients, tedious by default.
- mssql-ng - Next generation ES6-template interface for SQL (uses mssql/tedious).
- Install MongoDB on Windows
- Install the MongoDB npm package in the project root by running
npm install mongodb
- (Optional, but helpful for IntelliSense support in Visual Studio Code) Install the type definition file for MongoDB with
tsd install mongodb
- Load the mongodb module:
var MongoClient = require('mongodb').MongoClient;
- Determine your MongoDB connection string URI and set it to a variable:
var mongoUrl = '...'
;
Example: mongodb://localhost:27017/yourDatabaseName
💡 MongoDB by default listens on 27017, but to verify this open the MongoDB log file
mongod.log
in the log directory and navigate the line that shows the port number (i.e.[initandlisten] waiting for connections on port 27017
)
- Access your MongoDB database by calling
MongoClient.connect()
and query the returned database
MongoClient.connect(mongoUrl, function (err, db) {
if (!err) {
// query the collection and return a cursor to use
// to access the data
//
// note: calling find() with no parameters is the equivalent
// of pulling all documents in the collection with no
// predicate
var cursor = db.collection('yourCollectionName').find();
// loop through all of the documents returned by the
// query
cursor.each(function (err, element) {
if (!err && element) {
// do something with the document
}
// if error and the document are undefined then
// we have reached the no-more-documents condition
if (!err && !element) {
console.log('done!');
}
});
}
});
- azure - Full client for azure
- azure-storage - client for Azure Storage services (Tables, Blobs, Files, Queues), which is part of the
azure
module above. - azure-storage-simple - Promise based interface wrapper around
azure-storage
with a simpler UI.
Sometimes you need to access plaform functionality for which no suitable module is available. For example your app may need to access the registry running on a Windows Server or Desktop. In this case there are 2 ways to proceed.
- Create a native module add-on by wrapping code in C binding boilerplate code using the V8 sdk and dev tools.
- Use ref and node-ffi modules to access C buffers and call shared library (DLL) functions from javascript.
There are plenty of examples of creating native modules, including our notes on Compiling native addon modules but less on using ref and node-ffi.
💡 Note it is good practice to ensure published modules are [written to run on all platforms](building-for-cross-platform.md#writing-cross-platform-modules-and apps), even though this can be conciderable extra work. Modules that only work on Windows or Linux are likely to unpopular so such code is best restricted to private modules or app code.