Minimal Node.js docker container
Bitnami recently releases a prod version of their bitnami-docker-node with much smaller size due to stripping a bunch of unncessary stuff for runtime.
If your app does not require compiling native modules, you can use it as is. No changes required.
However, if you do need to compile native modules, you can still use their development image as builder and copy stuff over to prod image after.
I try with one of my app and the final image size reduce from 333 MB down to just 56 MB 💪 !
Official Oracle driver for Node.JS
Currently at v0.2. node-oracledb makes use of C API for performance which makes it more like a “thick client”. That mean you are required to install Oracle’s client lbiraries1. Though versioned as 0.2, node-oracledb already supports a lot of features such as connection pooling, statement caching, client-result caching, etc…
node-oracledb is not yet available through npm. You will have to clone and run npm install manually by yourself. Windows support is still pretty rough but I don’t actually care much.
Some of the most useful tips I learn when working with NodeJS
modules management with npm # Nodejs comes with an amazing package manager called npm. Start a project with npm init which will then create a configuration file named package.json, keeping track of all the modules your project is using. You don’t have to manually manage this file yourself. If you want to add a package to package.json you can add --save parameter when installing it.
npm install koa-static --save Also, you should ignore npm_modules folder when git push because whoever clone the repo can do npm install by themselves.
REST APIs made easy with StrongLoop
StrongLoop allows you to quickly create REST APIs using their graphic interface and CLI. SLC also supports debugging, profiling, tracing, deploying as well as monitoring features.
Creating REST APIs with slc is as easy as creating datasource and model. StrongLoop will do the rest for you.
I was very tempted to use StrongLoop for a recent project but I had to deal with a legacy database that use a very old odbc driver which force me to use node.
Fuck callbacks! Let’s use generators
Let’s write a simple function hello that return a string when called.
var hello = function () { return 'Hello ' + name; } Now convert it into a generator. Call hello() this time will return you an Object instead: the generator.
var hello = function *() { return 'Hello ' + name; } Let’s consider the following snippet.
var hello = function *() { yield 'Stopped here!'; return 'Hello ' + name; } var generator = hello('Clark Kent'); console.
Scaling node.js application with cluster
node.js’s single thread default architecture prevents it from utilizing multi-cores machines. When you create a new node.js application in WebStorm for example, this is what you get:
var debug = require('debug')('myApp'); var app = require('../app'); app.set('port', process.env.PORT || 3000); var server = app.listen(app.get('port'), function() { debug('Express server listening on port ' + server.address().port); }); // in app.listen method app.listen = function(){ var server = http.createServer(this); return server.listen.apply(server, arguments); }; This code snippet will create a simple HTTP server on the given port, executed in a single-threaded process; doesn’t matter how many cores your machine has.
io.js v1.0.0 released
A fork of node.js with faster release cycle and open source governance. io.js v1.0.0 also marks the return of Ben Noordhuis with third most commits in node.js as a technical commitee.
For those who don’t know about Ben Noordhuis’s story1. Here’s a short version:
Ben Noorddhuis was a major contributor to NodeJS and a voluntee
Ben Noorddhuis rejected a pull request2 that would have made pronoun in the document gender neutral.
How to fix Logon failed for login 'username' due to trigger execution
error with mssql
How to fix
Logon failed for login 'username' due to trigger execution
error with SQL Server