Wednesday, July 27, 2016

ColdFusion to Node.js Conversion Part 1

This multi-part post will be community comment driven, which basically means that in an effort to not spend too much time on details that might not matter to the viewers out there, I am only going to share the details which I think are important at the time of publishing the posts. If people (or bots) comment and want more details, I will add them to the original post. As always, constructive criticism is always welcome.

Since I am currently using the CFWheels framework (which is inspired by Ruby on Rails or RoR), I chose to try out the Sails.js framework for Node.js (which is also similar to Rails).

1st thing I did was get Node and Apache working together by adding this to my Apache vhost(VirtualHost) block:
ProxyRequests on
ProxyPass / http://localhost:8124/
And adding this to my hosts file (/etc/hosts):
127.0.0.1       mynewapp.node www.mynewapp.node

This allows me to setup an alias in my host file and reference the URL as you normally would without adding the portnumber on the end of the URL. Instead of having to use http://localhost:8124/ , I can now use http://mynewapp.node
After that I installed the "sails-mysql" npm package in order to get the app working with my existing MySQL database.
npm install sails-mysql --save

The next thing I did, because one very frustrating thing you will find is that you have to "lower" then "re-lift" your sails app after every change you make. I installed sails-hook-autoreload to take care of this for me as I make code changes.
npm install sails-hook-autoreload --save-dev
// I used "--save-dev" instead of "--save" above because this package is not required in a production setting.
NOTE: create a "[your-sails-app]/config/autoreload.js" file with at least the following configuration:
module.exports.autoreload = {
  active: true,
  overrideMigrateSetting: false
};
Otherwise the overrideMigrateSetting will be defaulted to true and sets the "module.exports.models.migrate" setting to "alter" which will wipe out any database tables you have setup models for!! This is a good time to mention taking frequent backups of your database. Since I am using an existing MySQL database I am using the "module.exports.models.migrate = safe" setting for both development and production environments.

to be continued....

No comments:

Post a Comment