<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Bacon Applications]]></title><description><![CDATA[Follow me while I share with the world useful things I have learned and projects I am working on.]]></description><link>http://www.baconapplications.com/</link><image><url>http://www.baconapplications.com/favicon.png</url><title>Bacon Applications</title><link>http://www.baconapplications.com/</link></image><generator>Ghost 3.7</generator><lastBuildDate>Wed, 19 Mar 2025 16:21:21 GMT</lastBuildDate><atom:link href="http://www.baconapplications.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Setting Up WPA2 on Raspberry Pi Running Raspbian Jessie Lite]]></title><description><![CDATA[There are several years' worth of setting up the Edimax EW-7811N Wi-Fi adapter on a Raspberry Pi B on the internet.  By now (2017) most of it is out of date]]></description><link>http://www.baconapplications.com/setting-up-wpa2-on-raspberry-pi-running-raspbian-jessie-lite/</link><guid isPermaLink="false">5e535ef4ba89970001e0b062</guid><category><![CDATA[Debian]]></category><category><![CDATA[Raspberry Pi]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Tue, 07 Feb 2017 05:06:00 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/cover.png" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/cover.png" alt="Setting Up WPA2 on Raspberry Pi Running Raspbian Jessie Lite"><p>There are several years' worth of setting up the Edimax EW-7811N Wi-Fi adapter on a Raspberry Pi B on the internet.  By now (2017) most of it is out of date and wrong.  Last week, I wasted several hours trying to make WPA2 authentication work on my Raspberry Pi B.  Hopefully this guide will save someone (or future me) some time.</p>
<h2 id="myhardware">My Hardware</h2>
<img style="height:150px;padding-right:50px;display:inline-block;" align="left" src="http://www.baconapplications.com/content/images/posts/piwpa2wifi/box.png" alt="Setting Up WPA2 on Raspberry Pi Running Raspbian Jessie Lite">
<ul>
<li>Edimax EW-7811N</li>
<li>Raspberry Pi B Revision 2</li>
<li>Rapbian Jessie Lite 1/11/2017</li>
</ul>
<p><br><br><br><br></p>
<h2 id="gettingstarted">Getting Started</h2>
<p>Roll back any changes you have made to the /etc/network/interfaces or /etc/wpa_supplicant/wpa_supplicant.conf files.  I usually make .bak copies of config files before I make changes.  However, if you did not make backups of these files, the contents of each original file is below.</p>
<h3 id="etcnetworkinterfaces">/etc/network/interfaces</h3>
<pre><code># interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

#iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
</code></pre>
<h3 id="etcwpa_supplicantwpa_supplicantconf">/etc/wpa_supplicant/wpa_supplicant.conf</h3>
<pre><code>country=US                                                
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev   
update_config=1                                           
</code></pre>
<p>Additionally, I had installed WICD at some point while trying to configure the adapter.  WICD will eat up to 5% of CPU in idle so you will want to uninstall it if you journeyed down the same rabbit hole I did...</p>
<h3 id="restart">RESTART</h3>
<p>Before continuing (and wasting more of your precious time) RESTART your Pi  (sudo reboot or sudo shutdown -r now).  I probably wasted another 30 minutes with a working solution because I hadn't restarted...</p>
<h2 id="usb">USB?</h2>
<p>Make sure the Wi-Fi adapter is plugged in and showing via the <em>lsusb</em> command:</p>
<img src="http://www.baconapplications.com/content/images/posts/piwpa2wifi/lsusb.png" alt="Setting Up WPA2 on Raspberry Pi Running Raspbian Jessie Lite" class="img-responsive">
<p>The Wi-Fi adapter should be show as &quot;Edimax Technology Co...&quot; as per above.  If it is not showing up, try unplugging and plugging in the adapter and/or restarting.</p>
<h2 id="settingupwpa2">Setting Up WPA2</h2>
<p>To set up WPA2 authentication, you will only need to edit the /etc/wpa_supplicant/wpa_supplicant.conf file.  Edit this file with the following:</p>
<pre><code>country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid=&quot;YOURNETWORKSSIDHERE&quot;
psk=&quot;YOURPASSWORDHERE&quot;
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
group=CCMP
auth_alg=OPEN
}
</code></pre>
<p>Replace YOURNETWORKSSIDHERE with your SSID and YOURPASSWORDHERE with your Wi-Fi password.</p>
<p>At this point restart your Pi.</p>
<p>Once your Pi has restarted fully, run the <em>ifconfig</em> command to confirm your adapter is getting an IP address.  The wireless link should be next to wlan0 or wlan1 in the dump:</p>
<img src="http://www.baconapplications.com/content/images/posts/piwpa2wifi/ifconfig.png" alt="Setting Up WPA2 on Raspberry Pi Running Raspbian Jessie Lite" class="img-responsive">
<h2 id="nosleep">No Sleep</h2>
<p>Finally, if your Pi needs to have Wi-Fi on at all times, be sure to disable power management by creating or editing the /etc/modprobe.d/8192cu.conf file via sudo nano /etc/modprobe.d/8192cu.conf:</p>
<pre><code># Disable power management
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
</code></pre>
<p>After this change, restart your Pi again.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I you found this guide helpful and hopefully it saved you some time!  Until next time - happy coding!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Export a VirtualBox Machine to VMware]]></title><description><![CDATA[Learn how to export a VirtualBox VM to VMware ESXi.  Also includes tips on how to resolve errors when trying to import the OVF file.]]></description><link>http://www.baconapplications.com/export-a-virtualbox-machine-to-vmware/</link><guid isPermaLink="false">5e535ef4ba89970001e0b061</guid><category><![CDATA[Virtualization]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Thu, 26 Mar 2015 18:58:07 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/export-vm-cover.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/export-vm-cover.jpg" alt="Export a VirtualBox Machine to VMware"><p>Recently I had to set up a virtual machine (VM) that would mirror a VirtualBox VM pretty closely.  I really didn't want to have to start over with a fresh machine set up so I decided to try to export the VirtualBox machine to our VMware host.  After some trial and error I was able to get it to work.</p>
<p>The versions of software used is as follows:</p>
<ul>
<li>VirutualBox ~4.3</li>
<li>vSphere Client ~5.1</li>
<li>VMware ESXi ~5.1</li>
</ul>
<h3 id="exportthevm">Export the VM</h3>
<p>To begin you will need to export the VirtualBox machine.  First shut down the machine and choose &quot;File&quot; &gt; &quot;Export Appliance&quot;.  Next select the machine you wish to export and click &quot;Next&quot;.</p>
<p><img src="http://www.baconapplications.com/content/images/posts/export-virtualbox-to-vmware/1-select-machine.png" alt="Export a VirtualBox Machine to VMware"></p>
<p>On the following screen, select a destination for the output file and choose the OVA format and choose &quot;OVF 1.0&quot;  format from the drop down and check the write manifest file box.</p>
<p><img src="http://www.baconapplications.com/content/images/posts/export-virtualbox-to-vmware/2-ovf-settings.png" alt="Export a VirtualBox Machine to VMware"></p>
<p>Click &quot;Next&quot; and then click &quot;Export&quot;.  Depending on the size of the machine this could take a while.</p>
<h3 id="preparingtoimportthevm">Preparing to Import the VM</h3>
<p>Once the export is complete you can try deploy the OVA to ESXi but you will receive the following error, &quot;The OVF package requires unsupported hardware.  Details: Line 25: Unsupported hardware family 'virtualbox-2.2'.&quot;.</p>
<p><img src="http://www.baconapplications.com/content/images/posts/export-virtualbox-to-vmware/2a-ovf-import_fail.png" alt="Export a VirtualBox Machine to VMware"></p>
<p>To fix this error, you will need to edit the OVF xml file in the OVA package.  The OVA package wraps an OVF file, a mf checksum file and the actual vmdk or virtual machine disk.  To extract the contents of this file, use 7Zip (right click &gt; &quot;7Zip&quot; &gt; &quot;Open Archive&quot;) to extract the OVA contents.  When you open the archive, you may receive a TAR error.  You can just click &quot;OK&quot; to ignore it.</p>
<p><img src="http://www.baconapplications.com/content/images/posts/export-virtualbox-to-vmware/3-extract-archive.png" alt="Export a VirtualBox Machine to VMware"></p>
<p>Make a backup copy of the OVF file and then open the OVF file with a text editor such as notepad++.</p>
<p>Change the following line:</p>
<pre>
&lt;vssd:VirtualSystemType&gt;virtualbox-2.2&lt;/vssd:VirtualSystemType&gt;
</pre>
<p>to</p>
<pre>
&lt;vssd:VirtualSystemType&gt;vmx-07&lt;/vssd:VirtualSystemType&gt;
</pre>
<p>After you have made this change, the checksum in the mf file will no longer match.  To fix this error, you can just remove the line that references the OVF file. For reference, my file looked like this:</p>
<pre>
SHA1 (MyVM.ovf)= 15d2f22b24990179e414df556fe4a2e4697caee7
</pre>
<h3 id="importthevm">Import the VM</h3>
<p>At this point you can try to attach the VM to your VMware box.  Open the VMware vSphere client and connect to your host machine.  Now choose file &quot;Deploy OVF Template&quot;.  Select the OVF file you just edited and click next.  Make sure to select the OVF file, not the original OVA file.</p>
<p>At this point, you may receive a hardware error: &quot;The OVF package requires unsupported hardware.  Details: Line 74: OVF hardware element 'ResourceType' with instance ID '6'.  No support for the virtual hardware device type '35'.&quot;</p>
<p><img src="http://www.baconapplications.com/content/images/posts/export-virtualbox-to-vmware/4-hardware-error.png" alt="Export a VirtualBox Machine to VMware"></p>
<p>To fix this error, open the OVF file and remove the &lt;item&gt; element at the line # in question. In this case it was the sound card:</p>
<pre>
	&lt;Item&gt;
        &lt;rasd:AddressOnParent&gt;3&lt;/rasd:AddressOnParent&gt;
        &lt;rasd:AutomaticAllocation&gt;false&lt;/rasd:AutomaticAllocation&gt;
        &lt;rasd:Caption&gt;sound&lt;/rasd:Caption&gt;
        &lt;rasd:Description&gt;Sound Card&lt;/rasd:Description&gt;
        &lt;rasd:ElementName&gt;sound&lt;/rasd:ElementName&gt;
        &lt;rasd:InstanceID&gt;6&lt;/rasd:InstanceID&gt;
        &lt;rasd:ResourceSubType&gt;ensoniq1371&lt;/rasd:ResourceSubType&gt;
        &lt;rasd:ResourceType&gt;35&lt;/rasd:ResourceType&gt;
	&lt;/Item&gt;
</pre>
<p>After you have made these adjustments to the OVF, try to load the file again.  If you happened to leave the select OVF window open, you may not be able to select the OVF file from the browse or the drop down list selector.  Just cancel and try again.</p>
<p>At this point you should get something like the following when you click next after selecting the modified OVF:</p>
<p><img src="http://www.baconapplications.com/content/images/posts/export-virtualbox-to-vmware/5-ovf-import.png" alt="Export a VirtualBox Machine to VMware"></p>
<p>Now follow the prompts to finish importing your machine:</p>
<ul>
<li>
<p>Click &quot;Next&quot; and enter (or verify) the name</p>
</li>
<li>
<p>Click &quot;Next&quot; and adjust Disk formatting if you wish</p>
</li>
<li>
<p>Click &quot;Next&quot; and verify the network</p>
</li>
<li>
<p>Click &quot;Next&quot; and click &quot;Finish&quot;</p>
</li>
</ul>
<p>At this point, you will need to wait a few minutes for the VM to deploy.  Once the machine has deployed, open the machine settings and make any adjustments you wish, such as memory or network adapter settings.</p>
<p><img src="http://www.baconapplications.com/content/images/posts/export-virtualbox-to-vmware/6-machine-adjustments.png" alt="Export a VirtualBox Machine to VMware"></p>
<p>To complete your machine import, power on the machine and remove VirtualBox Guest Additions and install the VMware Guest Tools.  Note: After the machine boots up and you log in, Windows will try to add hardware, click &quot;Cancel&quot; until you are installing the VMware Guest Tools.</p>
<p>First remove VirtualBox Guest Additions and restart.  After the machine restarts, install the VMware Guest Tools.  After the final restart you should have your VirtualBox machine running on VMware.</p>
<h3 id="closingthoughts">Closing Thoughts</h3>
<p>I have been able to move quite a few VMs and physical machines to VMware after some adjustments.  I hope this helps someone else in the future with their virtualization needs.  Until next time - happy coding!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Random Useful Information Part 1]]></title><description><![CDATA[Random useful information including blog writing tips, dynamic DNS, cool Google tools and more!]]></description><link>http://www.baconapplications.com/random-useful-information-part-1/</link><guid isPermaLink="false">5e535ef4ba89970001e0b060</guid><category><![CDATA[Random Useful Info]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Mon, 26 Jan 2015 19:50:56 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/cover.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/cover.jpg" alt="Random Useful Information Part 1"><p>I enjoy learning and sharing with others what I have learned but sometimes these little things I learn are not enough to actually write a whole blog post about.  To make up for this, I have decide to start something new called Random Useful Information.  I hope you find one of these tips useful.</p>
<h3 id="blogpostwritingtools">Blog Post Writing Tools</h3>
<h4 id="markdown">Markdown</h4>
<p>If you are using Ghost to create and manage your blog, you may be in love with the interface and resource usage but a little disappointed in the editor.  Don't get me wrong, the default editor in Ghost is great, but the lack of spell checking is really a no-go for me.  After some searching and trying several markdown editors, I decided to use <a href="http://markdownpad.com/" target="_blank">MarkdownPad 2</a>.</p>
<p>The only con for me in regards to this application is that it is Windows only.  I would love to use the same application on my Mac without having to use VirtualBox...</p>
<p>I decided to purchase the full version for the following reasons:</p>
<ul>
<li>To support the developer (I highly encourage this ;-)</li>
<li>The ability to customize the editor (I HATE having to edit on a white background in any application)</li>
<li>The ability to link in custom style sheets.  I created a style sheet that is very close to this site so the live preview will be very close to what is actually published.</li>
<li>Auto-save - this feature LITERALLY kept me from having to rewrite a couple of paragraphs in my last post</li>
<li>Commercial use - I can dream of someday being a real writer right?</li>
</ul>
<h4 id="git">Git</h4>
<p>Yes I actually started storing all my articles and related content in a Git repository.  I create a directory for each article with a unique images directory.  As I'm writing (or maybe when I am done), I commit my changes to Git and have an automatic back up.</p>
<h4 id="gist">Gist</h4>
<p>To share code, I use GitHub's <a href="https://gist.github.com/" target="_blank">Gist</a>.  If you already have a GitHub account, it is easy to set up Gists.  Also you can mark these Gists as private to just share with only others that have access to the Gist link.</p>
<h4 id="capitalizeyourtitle">Capitalize Your Title</h4>
<p>Do you remember all those rules from English class about title capitalization?  I don't either, but this little website <a href="http://titlecapitalization.com/" target="_blank">titlecapitalization.com</a> will do it for you.</p>
<h3 id="dynamicdns">Dynamic DNS</h3>
<p>Several times in the last month, Comcast has randomly decided to assign me a new IP address at home.  I have NAT set up on my router, along with an open port forwarding to my machine for remote desktop.  In the past, I have tried to keep an A record up-to-date on my DNS but it was becoming a pain.  <a href="https://www.duckdns.org" target="_blank">DuckDNS</a> is a great free option to keep track of your home machine IP.  To set up DuckDNS first go to the site and log in via the top right using an OAuth service.  The authors have decided to not maintain their own user store, so you will have to use a service to log in.</p>
<p>Once you have logged in, create a domain for the machine you want to track.  I am using the <a href="https://www.duckdns.org/install.jsp?tab=windows-powershell" target="_blank">Windows Powershell script</a> to keep my entry up-to-date.  This Powershell script runs every 5 minutes and persists after restart.  To check the status of this Powershell script, you can use the following Powershell command:</p>
<pre>
 Get-Job | foreach{ $_.Name + ' ' + $_.PSBeginTime + ' ' + $_.State }
</pre>
<h3 id="findingyouripviagoogle">Finding Your IP via Google</h3>
<p>This is a quick tip - go to google.com and enter &quot;what is my IP&quot; in the search box.  Amazing right?</p>
<h3 id="dnstools">DNS Tools</h3>
<p>Recently I moved my domains to a new web server on a completely new IP.  I found several tools that were very useful in this process.  The first is <a href="http://www.intodns.com/" target="_blank">intoDNS</a>.  This service offers a full dump of all things DNS related to your domain.</p>
<p>Google offers a free DNS lookup tool via the Google Apps Toolbox at <a href="https://toolbox.googleapps.com/apps/dig/" target="_blank">https://toolbox.googleapps.com/apps/dig/</a>.  Additionally in this Apps Toolbox, the <a href="https://toolbox.googleapps.com/apps/browserinfo/" target="_blank">Browserinfo section</a> is very useful.</p>
<p>Flush Google's public DNS cache for a record can be done via <a href="https://developers.google.com/speed/public-dns/cache" target="_blank">https://developers.google.com/speed/public-dns/cache</a>.</p>
<p>Additionally, sometimes Google Chrome will seem to get &quot;stuck&quot; on bad DNS records.  If you open chrome://net-internals/#dns in Chrome, you can click a button to clear the host cache.</p>
<h3 id="removingreallylongfilenamesinwindows">Removing Really Long File Names in Windows</h3>
<p>Recently I botched a Robocopy and ended up with a bunch of recursive directories that I could not remove because the files paths were &quot;too long&quot;.  I guess that is a &quot;feature&quot; of Windows.  I found this tip via <a href="http://stackoverflow.com/questions/551072/how-to-delete-a-long-path-in-windows/3320317#3320317" target="_blank">Stack Overflow</a>.  To remove the bunk directory, create a temp empty directory and use the following command:</p>
<pre>
robocopy empty_dir base_nested_dir /purge
</pre>
<h3 id="fixedorphanedusersinmssql">Fixed Orphaned Users in MSSQL</h3>
<p>After restoring a backup in MSSQL, you will often end up with &quot;orphaned&quot; users.  Here are a few quick commands to help fix these accounts:</p>
<pre>
--list all orphaned users
EXEC sp_change_users_login 'Report'

--fix the user
EXEC sp_change_users_login 'Auto_Fix', 'user'

--create a new user for a give user
--EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'

--delete user
--DROP USER user
</pre>
<h3 id="conclusion">Conclusion</h3>
<p>Hopefully you found one of these random items useful.  Until next time - happy coding!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Installing and Securing MongoDB on Windows]]></title><description><![CDATA[Quickly learn how to install and secure MongoDB on Windows for development.  Also learn how to create a secure log in and a new database.]]></description><link>http://www.baconapplications.com/installing-and-securing-mongodb-on-windows/</link><guid isPermaLink="false">5e535ef4ba89970001e0b05f</guid><category><![CDATA[MongoDB]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Mon, 19 Jan 2015 22:53:41 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/cover-1.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/cover-1.jpg" alt="Installing and Securing MongoDB on Windows"><p>Generally I have found that for the sake of speed, installing MongoDB on Windows isn't the best solution in production.  However for development, this might be your only or best option. Having a local installed MongoDB is convenient and useful for quickly prototyping concepts.</p>
<h3 id="downloadmongodb">Download MongoDB</h3>
<p>To install MongoDB first download and run the installer from <a href="http://www.mongodb.org/downloads" target="_blank">http://www.mongodb.org/downloads</a>.</p>
<p>Run the installer and advance to the following screen and click &quot;Custom&quot;:</p>
<p><img src="http://www.baconapplications.com/content/images/posts/mongodb-windows/customize_installer.png" alt="Installing and Securing MongoDB on Windows"></p>
<p>Expand the tree and select all options except &quot;Router&quot;.  You will only need to install the MongoDB router for a distributed DB and chances are for development you will not need this option.  If you think you might need this option, go ahead and install it.  Before clicking &quot;Next&quot; - select the root item and click &quot;Browse...&quot; to choose a new directory on a root drive (such as C:/).  I <em>highly</em> recommend this as it will make running command line tools much easier without having to use an administrator command prompt.  I will be using E:/mongoDB for my install.</p>
<p><img src="http://www.baconapplications.com/content/images/posts/mongodb-windows/select_options.png" alt="Installing and Securing MongoDB on Windows"></p>
<p>To finish the installation, click &quot;Next&quot; and &quot;Install&quot;.</p>
<h3 id="testingtheinstall">Testing the Install</h3>
<p>Once the installer has finished, you should test the install.  First you should create a data and log directory for the install.  I will use E:/mongoDB/data and E:/mongoDB/logs for both.</p>
<p>Once you have created these directories, open a <a href="http://windows.microsoft.com/en-us/windows/command-prompt-faq#1TC=windows-8" target="_blank">command prompt</a> and direct it to your install directory - E:/mongoDB/bin.  The bin directory is the root for all install MongoDB related programs and tools.  Run the following command to start MongoDB:</p>
<pre>
	E:\mongodb\bin\mongod --dbpath E:\mongodb\data
</pre>
<p>Leave this command prompt window running and start another command prompt and again direct it to your MongoDB directory.  Run this command to connect to the MongoDB server:</p>
<pre>
	E:\mongodb\bin\mongo
</pre>
<p>You should now see a prompt.  Try running the command &quot;show databases&quot; to see if the server is running correctly.</p>
<p><img src="http://www.baconapplications.com/content/images/posts/mongodb-windows/mongo_first_connect.png" alt="Installing and Securing MongoDB on Windows"></p>
<p>To exit this connection, type exit.  To end the server session, enter control+C.</p>
<h3 id="settinguptheconfigurationformongodb">Setting up the Configuration for MongoDB</h3>
<p>Before setting up MongoDB to run as a service, you should take a minute to set up the default configuration for your install.  Navigate to your install directory and create a mongod.cfg file.  Add the following lines to this file:</p>
<script src="https://gist.github.com/baconapplications/eb6d970ab893b4413c99.js"></script>
<p>Test your new db configuration via the following:</p>
<pre>
	E:\mongodb\bin\mongod --config=E:\mongodb\mongod.cfg
</pre>
<p>In another command prompt window connect to the service via the IP and port as follows:</p>
<pre>
	E:\mongodb\bin\mongo 127.0.0.1:37011 
</pre>
<h3 id="settingupmongodbtorunasaservice">Setting up MongoDB to Run as a Service</h3>
<p>You can use the installed MongoDB application itself to set up MongoDB to run as a service, but I like to have a little more control over the service install.  Use the following line to set up the service.  NOTE: You will need to run this command from an administrator command prompt.</p>
<pre>
sc.exe create MongoDB binPath= "\"E:\mongoDB\bin\mongod.exe --service --config=E:\mongoDB\mongod.cfg\" DisplayName= "MongoDB" start= "auto"
</pre>
<p>Once the service is created, start the service from the Services control panel or use the following to start the service:</p>
<pre>
net start MongoDB
</pre>
<p>Again, using the command prompt above, connect to the service using the mongo executable on port 37011.</p>
<p>To delete the service, run the following from an administrator command prompt:</p>
<pre>
net stop MongoDB
sc delete MongoDB
</pre>
<h3 id="troubleshootingserviceinstall">Troubleshooting Service Install</h3>
<p>If you followed the steps above and you receive an error message, make sure the line to add a service is entered exactly as above.  The spacing and quotes are important for the service to be added correctly.</p>
<h3 id="securingyourmongodbinstall">Securing Your MongoDB Install</h3>
<p>Security is not enforced in the default install of MongoDB.  If you want to enable security, follow the next steps.  I like to enable security on my install so that my development environment will be closer to production.</p>
<p>First log into your install and create a DB admin user:</p>
<pre>
mongo 127.0.0.1:37011/admin
use admin
db.createUser(
  {
    user: "mongoadmin",
    pwd: "p@ssw0rd",
    roles:
    [
      {
        role: "userAdminAnyDatabase",
        db: "admin"
      }
    ]
  }
)
</pre>
<p>Once you have added the mongoadmin user, quit mongo and add the following to the mongod.cfg you created earlier.</p>
<pre>
auth=true
</pre>
<p>After adding the above to the cfg file, restart the MongoDB service.  Now you will need to use the username and password to access the databases.  If you try to connect to the MongoDB service without credentials and run the &quot;show databases&quot; command, you will see an error:</p>
<p><img src="http://www.baconapplications.com/content/images/posts/mongodb-windows/invalid_creds.png" alt="Installing and Securing MongoDB on Windows"></p>
<p>However using the following to connect, you will be able view the databases:</p>
<pre>
mongo 127.0.0.1:37011/admin --username mongoadmin --password
</pre>
<p><img src="http://www.baconapplications.com/content/images/posts/mongodb-windows/valid_creds.png" alt="Installing and Securing MongoDB on Windows"></p>
<h3 id="creatinganewdatabase">Creating a New Database</h3>
<p>Now you finally have your MongoDB service up and running.  The next step is to create a new database with a unique user.  First log into the admin db with your admin user:</p>
<pre>
mongo 127.0.0.1:37011/admin --username mongoadmin --password
</pre>
<p>Next use the following commands to create a new database with the mongoadmin user and a database user:</p>
<pre>
use testDB1
db.createUser(
  {
    user: "mongoadmin",
    pwd: "p@ssw0rd",
    roles:
    [
      {
        role: "dbOwner",
        db: "testDB1"
      }
    ]
  }
)

db.createUser(
  {
    user: "mydbuser",
    pwd: "test1234",
    roles:
    [
      {
        role: "readWrite",
        db: "testDB1"
      }
    ]
  }
)
</pre>
<p>To test the created user, quit the current mongo shell and log back in using the new database user as follows:</p>
<pre>
mongo 127.0.0.1:37011/testDB1 --username mydbuser
</pre>
<p>Finally create a new collection and return the result</p>
<pre>
db.test.insert({"name":"test value"})
db.test.find()
</pre>
<h3 id="conclusion">Conclusion</h3>
<p>Hopefully you found this guide helpful.  The MongoDB install guide is actually quite detailed now and can be found at <a href="http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/" target="blank">http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/</a>.  Until next time - happy coding!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Extending Interfaces of Existing Typescript Definitions]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>I honestly have a love/hate relationship with <a href="http://www.typescriptlang.org/">Typescript</a>.  Most of the time I enjoy the shortcuts created by using Typescript. Typescript has several positive features that help me code faster and smarter, such as quick access to model or class properties, the ability to jump to code using F12,</p>]]></description><link>http://www.baconapplications.com/extending-interfaces-of-existing-typescript-definitions/</link><guid isPermaLink="false">5e535ef4ba89970001e0b05e</guid><category><![CDATA[Typescript]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Thu, 06 Nov 2014 21:20:04 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/extendingTypescriptCover.png" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/extendingTypescriptCover.png" alt="Extending Interfaces of Existing Typescript Definitions"><p>I honestly have a love/hate relationship with <a href="http://www.typescriptlang.org/">Typescript</a>.  Most of the time I enjoy the shortcuts created by using Typescript. Typescript has several positive features that help me code faster and smarter, such as quick access to model or class properties, the ability to jump to code using F12, auto-complete on third-party and local libraries, and the layout of the resulting code structure.  However, there are several things that I struggle with using Typescript, the biggest one is using a method on an object that isn't in the Typescript definition file or a property you have added to a custom object.</p>
<h3 id="extendingleafletdefinitions">Extending Leaflet Definitions</h3>
<p>I have run into this several times using Angular and the <a href="http://tombatossals.github.io/angular-leaflet-directive">Leaflet Angular directive</a>.  The Leaflet Angular directive uses some models that are derivatives of the real underlying Angular models.  The marker model is one of these items.  Recently on a project I was working on, I could not get the following code to compile in Typescript.</p>
<pre>marker.focus = true;</pre>
<p>This is because I had declared this marker as the type L.Marker so I could access the methods that are shared by the Leaflet Angular directive object.  Of course this definition does not contain the focus method which is specific to the Leaflet Angular object.  I really didn't want to recreate definitions for this object.  To account for this, I created the following interface to extend the Typescript definition.</p>
<pre>
declare module L {
    interface AngularMarker extends Marker {
        focus: boolean;
    }
}
</pre>
<p>Then in the resulting code, the marker can be cast to our new type and Typescript will allow us to compile.</p>
<pre>(<l.angularmarker>marker).focus = true</l.angularmarker></pre>
<h3 id="closingthoughts">Closing Thoughts</h3>
<p>I hope this helps someone save some time in the future.  I was stuck on this one for about an hour near the end of a sprint and it was frustrating.  Until next time - happy coding!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Custom Publishing with Visual Studio 2013]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>If you read my <a href="http://www.baconapplications.com/running-bowergrunt-in-visual-studio-2013/" target="_blank">last post</a>, hopefully you implemented Bower into your next Visual Studio project.  If you are anything like me though, you probably noticed some files being published that you really didn't want to publish.  This caused me to do some digging to figure out how to remove</p>]]></description><link>http://www.baconapplications.com/custom-publish-with-visual-studio-2013/</link><guid isPermaLink="false">5e535ef4ba89970001e0b05d</guid><category><![CDATA[Visual Studio]]></category><category><![CDATA[Code]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Wed, 08 Oct 2014 18:30:38 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/vspublishingCover.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/vspublishingCover.jpg" alt="Custom Publishing with Visual Studio 2013"><p>If you read my <a href="http://www.baconapplications.com/running-bowergrunt-in-visual-studio-2013/" target="_blank">last post</a>, hopefully you implemented Bower into your next Visual Studio project.  If you are anything like me though, you probably noticed some files being published that you really didn't want to publish.  This caused me to do some digging to figure out how to remove these files from publishing.  Additionally I learned how to copy some files as well.  This is useful for custom file publishing such as replacing a globals.js file.</p>
<h3 id="tothecode">To the Code</h3>
<p>To get started create a blank MVC application in Visual Studio.  If you want to cheat and get a complete kick start, <a href="https://github.com/baconapplications/VS2013PublishFiles" target="_blank">click here</a> to pull an example project from my GitHub.</p>
<h4 id="examplepublishing">Example Publishing</h4>
<p>Once you have your example project set up, create a publishing profile.  I am only using file based publishing in this post (maybe a follow up post is needed...).  First start by publishing your project and selecting custom profile:</p>
<img src="http://www.baconapplications.com/content/images/posts/vspublish/publish.png" alt="Custom Publishing with Visual Studio 2013">
<p>Now select the publish method, file system, and enter the location where you would like your files to be published.</p>
<img src="http://www.baconapplications.com/content/images/posts/vspublish/publishMethod.png" alt="Custom Publishing with Visual Studio 2013">
<p>On the final screen, select the configuration you would like to use for publishing.  I also like to delete all my existing files and make sure not to include files from the App_Data folder.</p>
<img src="http://www.baconapplications.com/content/images/posts/vspublish/publishConfig.png" alt="Custom Publishing with Visual Studio 2013">
<p>When you are done, click publish to publish the files.</p>
<h3 id="timetocustomize">Time to Customize</h3>
<p>At this point, VS will create a publishing profile for you.  This is where you want to dig in and manually customize your publishing process.  Expand the Properties directory and then the PublishProfiles directory to see the publishing profile XML.</p>
<img src="http://www.baconapplications.com/content/images/posts/vspublish/publishSolutionExpl.png" alt="Custom Publishing with Visual Studio 2013">
<p>Once you open this file, you will see something like the below as the default:</p>
<img src="http://www.baconapplications.com/content/images/posts/vspublish/publishxmlPre.png" alt="Custom Publishing with Visual Studio 2013">
<p>First you will create a publishing action to remove some files and a directory.  To do this, you will be adding two new XML elements, ExcludeFilesFromDeployment and ExcludeFoldersFromDeployment to your pubxml file.  The first element removes files you do not wish to deploy and the second removes directories you do not wish to deploy.  The paths in both elements are relative to the project root.  For this example I added an ignoreme.txt file and a RemoveFolder directory to the root of the project.  Once you have made your edits, your pubxml file should look like the following:</p>
<script src="https://gist.github.com/baconapplications/e520ff6824a9bf22f504.js"></script>
<p>Save your changes and publish your project using this publishing profile.  You should see that the ignoreme.txt file, packages.config file and the RemoveFolder are not published to the publish directory.  SWEET!</p>
<p>The final example of custom publishing involves copying a file from an external location to the final published location.  This could be useful for something like replacing a global.js file.  Inside your solution but outside of your project, create 2 files in a solution folder - global.js and renamefile.js.  The contents of these do not matter.  You only need to be able to tell what file it is.  Additionally, in your scripts directory in your MVC project create another global.js file with different content in it.</p>
<p>Now you will be adding two additional targets and property groups to your pubxml file.  Add the &lt;Target Name=&quot;CopyGlobal&quot;&gt; and &lt;Target Name=&quot;CopyAndRename&quot;&gt; elements and the associated &lt;PropertyGroup&gt; elements to your pubxml file.  The result should look like the following:</p>
<script src="https://gist.github.com/baconapplications/f7d18b132c1b780fc740.js"></script>
<p>Assuming your project is structured the same as mine (you might need to verify the path of your global.js file), when you publish you should notice the global.js file in the scripts directory is your external file.  Additionally, you should now have the renamed config.js file.</p>
<p>If you want to copy more than one file, you can add additional &amp;;lt_CustomFiles&gt; elements to your target group.  If you use this method however, you will need to use this line</p>
<pre><code>&lt;DestinationRelativePath&gt;scripts\%(RecursiveDir)%(Filename)%(Extension)&lt;/DestinationRelativePath&gt;
</code></pre>
<p>to ensure the files are placed correctly.</p>
<p>Also note that <i>scripts&lt;/i&gt; directory is where the copied files will be placed.  If you want to use a different location you will need to adjust that.</i></p>
<h3 id="closingthoughts">Closing Thoughts</h3>
<p>Hopefully this will save you some time in publishing your project with custom build actions.  Although this isn't the Grunt of Visual Studio, it does allow some custom build actions without an additional bat file or script.  Until next time - happy coding!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Running Bower and Grunt in Visual Studio 2013]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Yes the title of this post is correct.  A recent extension for Visual Studio 2013 will let you run Grunt inside of Visual Studio.  Scott Hanselman gave a quick overview <a href="http://www.hanselman.com/blog/introducinggulpgruntbowerandnpmsupportforvisualstudio.aspx" target="_blank">here</a>, but honestly I had to stumble through implementing it the first time.  To save you some time read on!</p>]]></description><link>http://www.baconapplications.com/running-bower-grunt-in-visual-studio-2013/</link><guid isPermaLink="false">5e535ef4ba89970001e0b05a</guid><category><![CDATA[Grunt]]></category><category><![CDATA[Visual Studio]]></category><category><![CDATA[Bower]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Tue, 16 Sep 2014 18:32:35 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/vsGrunt.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/vsGrunt.jpg" alt="Running Bower and Grunt in Visual Studio 2013"><p>Yes the title of this post is correct.  A recent extension for Visual Studio 2013 will let you run Grunt inside of Visual Studio.  Scott Hanselman gave a quick overview <a href="http://www.hanselman.com/blog/introducinggulpgruntbowerandnpmsupportforvisualstudio.aspx" target="_blank">here</a>, but honestly I had to stumble through implementing it the first time.  To save you some time read on!</p>
<h3 id="preparingyourenvironment">Preparing Your Environment</h3>
<p>If you haven't done any work with NodeJS on your machine, you will need to do a few things to get your environment ready for this extension.  This extension is a wrapper for NodeJS, Git, Bower, Grunt, Gulp and npm.  If you haven't heard of or used any of these tools, I would recommend reading the following:</p>
<ul>
<li>
<p><a href="http://nodejs.org/" target="_blank">NodeJS</a> - Everyone seems to be talking about it.  It's a JavaScript based language that runs server-side.  Grunt uses Node to run its tasks.</p>
</li>
<li>
<p><a href="http://git-scm.com/" target="_blank">Git</a> - Git is a version control system that is distributed.  The Windows install is pretty unobtrusive.  If you have never used Git, give it a shot.  You may love it, I do now!</p>
</li>
<li>
<p><a href="http://bower.io/" target="_blank">Bower</a> - Bower installs client-side packages for the web, much like Nuget.  Bower uses the Git repository for the client-side packages instead of the package having to be maintained by someone for Nuget.</p>
</li>
<li>
<p><a href="http://gruntjs.com/" target="_blank">Grunt</a> - Grunt is a JavaScript task runner used to help with builds, downloading packages, minifying files, all sorts of fun things!</p>
</li>
<li>
<p><a href="http://gulpjs.com/" target="_blank">Gulp</a> - Gulp is another JavaScript task runner, but is code-driven instead of declaration driven.</p>
</li>
<li>
<p><a href="https://www.npmjs.org/" target="_blank">NPM</a> - Node packaged modules manager.  Think of NPM as something kind of like the Nuget of Node.  NPM is more powerful though as it allows you to install modules you can you use system wide, not just in your project.</p>
</li>
</ul>
<h3 id="whattoinstall">What to Install</h3>
<p>Here is the install order I would use for a fresh install.  As a guy who dabbles in Node, I had most of these installed.  You don't need to re-install any item below.  I would just make sure they are up-to-date.  For all the installers, the default options will be fine.</p>
<ul>
<li><a href="http://git-scm.com/downloads" target="_blank">Git</a></li>
</ul>
<p>A note about your Git install: if you choose to install and use the Git bash, like I do, you will need to add Git to your path.  Follow the directions <a href="http://blog.countableset.ch/2012/06/07/adding-git-to-windows-7-path/" target="_blank">here</a> to do that.  If installed correctly, typing git in a command prompt will display the git help screen.</p>
<ul>
<li><a href="http://nodejs.org/" target="_blank">NodeJS</a></li>
</ul>
<p>Once node is installed the following can be installed via NPM.  NPM is installed with Node on Windows.  Open a new command prompt and run the following commands.</p>
<pre><code>npm install -g bower
</code></pre>
<p>The above command will install the bower package globally (-g) so any Node script can access the package on your machine.  Now run the following 2 commands to finish all the installs we need.</p>
<pre><code>npm install -g grunt-cli

npm install -g gulp
</code></pre>
<p>Once that batch of nitty gritty installs is done, you can finally install the extension for Visual Studio.  <b><i>You must install Visual Studio 2013 service pack 3</i></b> to install this package.  If you haven't done that yet, check for updates in Visual Studio and install it.  Once service pack 3 is installed, install the extension by downloading it <a href="http://visualstudiogallery.msdn.microsoft.com/8e1b4368-4afb-467a-bc13-9650572db708" target="_blank">here</a>.</p>
<p>You will also need to install the following extensions to make your life a little easier:</p>
<ul>
<li><a href="http://visualstudiogallery.msdn.microsoft.com/65748cdb-4087-497e-a394-2e3449c8e61e" target="_blank">Package Intellisense</a> Adds NPM and Bower package Intellisense right in Visual Studio.</li>
<li><a href="http://visualstudiogallery.msdn.microsoft.com/dcbc5325-79ef-4b72-960e-0a51ee33a0ff" target="_blank">Grunt Launcher</a> Adds a right click option for Grunt and Gulp files.  Also allows you to do a right click, NPM install.</li>
</ul>
<h3 id="usinggruntandbowerinvisualstudio">Using Grunt and Bower in Visual Studio</h3>
<p>It's time for learning by example.  To see why anyone would go through this much work to set up an extension, check out the following sample.  First create a new <i>empty</i> web project.  You can use Grunt and Bower in any web project, but for this example, keep it simple.  If you want to cheat, you can check out the github for this example project <a href="https://github.com/baconapplications/BowerGruntInVS2013" target="_blank">here</a>.</p>
<h4 id="packagejson">package.json</h4>
<p>Once you have an empty web project, create the following package.json file.  The package.json file is used by Grunt to provide information to Grunt about your project.  These include the dev dependencies (what is needed to run your Grunt tasks) and the production (project) dependencies.  The package below will tell NPM to install grunt and some grunt related packages that will be used in your grunt file.</p>
<pre><code>{
    &quot;name&quot;: &quot;vs-grunt-example&quot;,
    &quot;version&quot;: &quot;0.0.1&quot;,
    &quot;description&quot;: &quot;Just a simple Grunt example - filled with fun and joy.&quot;,
    &quot;devDependencies&quot;: {
        &quot;grunt&quot;: &quot;~0.4.5&quot;,
        &quot;grunt-bower-task&quot;: &quot;~0.4.0&quot;,
        &quot;grunt-contrib-uglify&quot;: &quot;~0.5.1&quot;,
        &quot;grunt-contrib-concat&quot;: &quot;~0.5.0&quot;
    }
}
</code></pre>
<p><b>Once this package file is done,</b> you will need to run NPM.  Running NPM will install these packages and allow you to run your grunt script.  I am in the habit of running NPM right after I make changes to my package.json script.  To run NPM for your project, right click the package.json file and choose &quot;NPM install packages&quot;.</p>
<h4 id="bowerjson">bower.json</h4>
<p>Now create a bower.json file.  This file tells bower what you want your project to download and install in your project.  More information about the bower.json file can be found <a href="https://github.com/bower/bower.json-spec" target="_blank">here</a>.</p>
<pre><code>{
    &quot;name&quot;: &quot;vs-grunt-example&quot;,
    &quot;version&quot;: &quot;0.0.1&quot;,
    &quot;authors&quot;: [
        &quot;Randy Bacon &lt;randy@hirerandybacon.com&gt;&quot;
    ],
    &quot;description&quot;: &quot;Example using grunt and bower in VS2013&quot;,
    &quot;homepage&quot;: &quot;www.hirerandybacon.com/blog&quot;,
    &quot;dependencies&quot;: {
        &quot;jquery&quot;: null,
        &quot;leaflet&quot;: null,
        &quot;leaflet-plugins&quot;: null
    },
    &quot;exportsOverride&quot;: {
        &quot;leaflet-plugins&quot;: {
            &quot;control&quot;: &quot;control/*.js&quot;,
            &quot;css&quot;: &quot;css/*&quot;,
            &quot;layer&quot;: &quot;layer/*.js&quot;,
            &quot;layer/tile&quot;: &quot;layer/tile/*.js&quot;,
            &quot;layer/vector&quot;: &quot;layer/vector/*.js&quot;
        }
    },
    &quot;private&quot;: true
}
</code></pre>
<p>Note: When I tried a fresh solution on another machine, bower could not read the bower.json file.  It turned out the encoding was an issue.  To fix it open the bower.json file, choose &quot;Save As&quot;, click the arrow next to &quot;Save&quot;, choose &quot;Save with Encoding...&quot; and finally select &quot;Unicode (UTF-8 without signature)&quot; for the encoding and &quot;Unix (LF)&quot; for the line endings.</p>
<h4 id="gruntfilejs">Gruntfile.js</h4>
<p>Now create the Gruntfile.js.  This is where the magic happens.  If you are still with me, then my virtual hat is off to you.</p>
<pre><code>module.exports = function (grunt) {
    grunt.initConfig({
    	//this loads our packages for our grunt file
        pkg: grunt.file.readJSON('package.json'),
        
        //this section does our bower installs for us
        bower: {
            install: {
                options: {
                    targetDir: './scripts/vendor',
                    layout: 'byComponent',
                    install: true,
                    verbose: true,
                    cleanTargetDir: false,
                    cleanBowerDir: false,
                    bowerOptions: {}
                }
            }
        },
        
        //this section is used to join our js files together
        concat: {
            options: {
                separator: ';',
                stripBanners: true,
                banner: '/*! &lt;%= pkg.name %&gt; - v&lt;%= pkg.version %&gt; - ' +
                  '&lt;%= grunt.template.today(&quot;mm-dd-yyyy&quot;) %&gt; */',
            },
            devSrc: {
                src: ['scripts/vendor/jquery/*.js',
            'scripts/vendor/leaflet/*.js',
                    'scripts/vendor/leaflet-plugins/layer/tile/Google.js'],
                dest: 'scripts/vendor/dist/project-vendor-src.js',
            },
        },
        
        //this section is used to for our minify action
        uglify: {
            options: {
                banner: '/*! &lt;%= pkg.name %&gt; &lt;%= grunt.template.today(&quot;yyyy-mm-dd&quot;) %&gt; */\n'
            },
            build: {
                src: 'scripts/vendor/dist/project-vendor-src.js',
                dest: 'scripts/vendor/dist/project-vendor.min-&lt;%= pkg.version %&gt;.js'
            }
        }
    });

	//npm modules need for our task
    grunt.loadNpmTasks('grunt-bower-task');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-concat');

    //run bower for package install
    grunt.registerTask('install-bower-packages', ['bower']);

    //build vendor file src
    grunt.registerTask('merge-js-files', ['concat']);

    //build min vendor file from above
    grunt.registerTask('min-js-file', ['concat', 'uglify']);
};
</code></pre>
<h3 id="usingtaskrunnerexplorer">Using Task Runner Explorer</h3>
<p>Once your Gruntfile.js is complete, you can run the fancy Visual Studio Task Runner Explorer that this post is all about and watch the magic...</p>
<p>Right click on your Gruntfile.js file and choose Task Runner Explorer.  This will open up the tool that allows you to run your Grunt tasks. Note: if this option isn't showing up for you, try to quit and restart Visual Studio.   You should see something like the below:</p>
<img src="http://www.baconapplications.com/content/images/posts/vs-grunt-example/taskRunnerScreen.png" alt="Running Bower and Grunt in Visual Studio 2013">
<h4 id="runningbower">Running Bower</h4>
<p>Right click the install-bower-packages Alias Task and click run.</p>
<img src="http://www.baconapplications.com/content/images/posts/vs-grunt-example/taskRunnerInstallBower.png" alt="Running Bower and Grunt in Visual Studio 2013">
<p>The right window should now let you know bower is doing some work.  When this is done you probably will not see any changes in your Solution Explorer.  You will need to show all files in the Solution Explorer via this button:</p>
<img src="http://www.baconapplications.com/content/images/posts/vs-grunt-example/solutionExplorerShowAll.png" alt="Running Bower and Grunt in Visual Studio 2013">
<p>In order to see changes after running your grunt tasks, you will need to refresh your Solution Explorer. After refreshing, right click the scripts directory and select &quot;Include in Project&quot;. Now your solution should now look something like this:</p>
<img src="http://www.baconapplications.com/content/images/posts/vs-grunt-example/solutionExplorer.png" alt="Running Bower and Grunt in Visual Studio 2013">
<p>Congratulations!  You have just used Grunt to download and install js files in your project via bower.  Any time the Git repository changes, you can run this command to update the JS files you have referenced.  This is a very easy way to keep your JS files in sync with the Git for new versions and bug fixes.</p>
<h4 id="joiningourjsfiles">Joining Our JS Files</h4>
<p>The second task you created will join your vendor JS files you just installed into a single JS file.  This is helpful in dev (you only need to include a single file) and also makes creating a minified file of this file much faster.</p>
<p>Again go to the Task Runner Explorer and right click the merge-js-files Alias Task.  Again you will see a few messages in your command window to the right.  You can now refresh your scripts/vendor directory and you should see the dist directory.  Make sure to refresh your Solution Explorer and include the files in your project to use them.</p>
<h4 id="minifyingourjsfile">Minifying Our JS File</h4>
<p>The final task you created will minify your JS file for use in production.  Right click the min-js-file task and click run.  Again refresh the scripts/vendor/dist and you should see your new project-vendor.min-0.0.1.js file.  Sweet!</p>
<h3 id="gotchas">Gotchas</h3>
<p>A few issues I ran into while working on my grunt scripts:</p>
<ul>
<li>
<p>bower.json file encoding.  Selecting the default .json template in Visual Studio will not work with bower and you will have to make adjustments to the encoding per above.</p>
</li>
<li>
<p>Pretty bad error messages.  If you have an error in your package.json file, the command output is not really too helpful.</p>
</li>
<li>
<p>No bower search.  From the command line you can run <code>bower search item-to-search-for</code> to find matching gits.  There doesn't appear to be a way to do that via this tool.</p>
</li>
<li>
<p>Solution Explorer does not automatically add new files.  As you probably experienced above, the Solution Explorer does not show your bower installed files automatically.  This is a minor annoyance, but still a 'gotcha'.</p>
</li>
<li>
<p>NPM uninstalls - I was playing with different bower running packages and didn't like the first couple of packages I had installed.  I was unable to delete them via Windows explorer because the path of some of the nested files was too long.  To uninstall them, open a command prompt and browse to your web project directory.  Run the following to remove a package:</p>
<pre><code>	npm uninstall &lt;package name&gt;
</code></pre>
</li>
</ul>
<h3 id="closingthoughts">Closing Thoughts</h3>
<p>Hopefully you can see the power of using bower and grunt in your project.  It's a new world out there and Visual Studio is closing the gap between tools that are usually just used in Node or with Open Source tools.  I find this change exciting and I'm very happy to be able to use bower inside of Visual Studio.  Until next time - happy coding!</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Moving a NodeJS App to Production on Debian Wheezy]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>WOW! Moving this application (my new website and blog) to my Debian VPS was a little harder than I wanted and anticipated.  Of course this was my first time publishing a Node app to production so some learning time was to be expected...</p>
<h3 id="gettingreadyforproduction">Getting Ready for Production</h3>
<p>Before moving from</p>]]></description><link>http://www.baconapplications.com/moving-nodejs-app-to-production-on-debian/</link><guid isPermaLink="false">5e535ef4ba89970001e0b059</guid><category><![CDATA[NodeJS]]></category><category><![CDATA[Debian]]></category><dc:creator><![CDATA[Randy Bacon]]></dc:creator><pubDate>Mon, 08 Sep 2014 04:51:49 GMT</pubDate><media:content url="http://www.baconapplications.com/content/images/2020/02/gitCheckin.png" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="http://www.baconapplications.com/content/images/2020/02/gitCheckin.png" alt="Moving a NodeJS App to Production on Debian Wheezy"><p>WOW! Moving this application (my new website and blog) to my Debian VPS was a little harder than I wanted and anticipated.  Of course this was my first time publishing a Node app to production so some learning time was to be expected...</p>
<h3 id="gettingreadyforproduction">Getting Ready for Production</h3>
<p>Before moving from PHP to Node on my server I had read several articles and posts about different set ups.  I decided to move to NGINX from Apache as my web server. I have used Apache since my first FreeBSD server - about 15 plus years ago - but it was time to move forward to something faster and with a fun name.  Another post will follow about this move later...</p>
<p>Since I already had NGINX up and running I just needed to adjust my website config to the following (real ports are not below but would be the port of your apps):</p>
<pre><code>server {
	server_name www.hirerandybacon.com;

	location / {
    	proxy_pass http://localhost:&lt;NODEJSPORT&gt;;
    	proxy_http_version 1.1;
    	proxy_set_header Upgrade $http_upgrade;
    	proxy_set_header Connection 'upgrade';
    	proxy_set_header Host $host;
    	proxy_cache_bypass $http_upgrade;
	}

	location /blog {
    	proxy_pass http://localhost:&lt;NODEJSPORT&gt;;
    	proxy_http_version 1.1;
    	proxy_set_header Upgrade $http_upgrade;
    	proxy_set_header Connection 'upgrade';
    	proxy_set_header Host $host;
    	proxy_cache_bypass $http_upgrade;
	}
}
</code></pre>
<p>Additionally, I went the lazy route and published all my web files as is from the raw project.  I plan on building a Grunt script to help with this but for now it was all manual.</p>
<h3 id="whatdidntwork">What didn't work</h3>
<p>I tried several methods to get my node app up and running.  First I installed <a href="https://github.com/nodejitsu/forever" target="_blank"><i>forever</i></a> figuring it would be the easiest way (and I have heard others talking about it).  Running forever from the command line is as simple as (note: the NODE_ENV=production export is for my <a href="http://docs.ghost.org/" target="_blank">ghost</a> blog):</p>
<pre><code>NODE_ENV=production forever start app.js
</code></pre>
<p>The first issue I had found was a warning about sqlite3.  Because of my recent work with node-webkit I figured I needed to do an actual npm install on the machine to compile SQLITE.  I changed to the web directory of my project and ran:</p>
<pre><code>npm install sqlite3
</code></pre>
<p>Of course this yeilded some random error messages about permissions and also one of interest.  I was missing <i>make</i>.  So installing <i>make</i> was needed:</p>
<pre><code>sudo apt-get install build-essential
</code></pre>
<p>After running this, the base application started but now the ghost module was complaining about sqlite3 (the joys of developing on Windows and publishing to Debian).  I changed to the ghost directory inside of my web/node_modules directory and ran the npm install sqlite3 command again.</p>
<p>Finally this worked without issue and I was excited. Time to set it up to run via the cron.  Being the old school Unix guy I was (or maybe more accurately the lack of recent Unix experience) - I rushed to set up an init.d script.</p>
<p>I tried several init.d scripts from git and Google search results.  It seemed each had an issue and did not work well with my flavor of Debian - Wheezy.  Additionally, more errors were caused by creating the scripts on Windows and coping it to my Debian box.  Turns out carriage returns were the cause.</p>
<h3 id="whatfinallyworkedafterawhile">What finally worked after a while...</h3>
<p>After wasting some good football watching time with the init.d I decided to try something simpler from the <a href="http://support.ghost.org/deploying-ghost/" target="_blank">Ghost docs</a> - <a href="http://supervisord.org/" target="_blank">Supervisor</a>.  The installation and config was pretty easy.</p>
<pre><code>sudo apt-get install supervisor
</code></pre>
<p>On step 2 - <code>service supervisor start</code> I received the following a useless error message:</p>
<pre><code>Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
</code></pre>
<p>Great!  A quick google search though indicated I just needed to run this:</p>
<pre><code>sudo unlink /var/run/supervisor.sock
</code></pre>
<p>After running the command and trying again, the service was running.  I banged out a quick config for my node application and saved it to the config.d directory - /etc/supervisor/conf.d/ - (of course the real path below is a little different but you get the idea):</p>
<pre><code>[program:hirerandybacon]
command = node /mysecrectpath/app.js
directory = /mysecrectpath
user = www-data
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/hirerandybacon.log
stderr_logfile = /var/log/supervisor/hirerandybacon_err.log
environment = NODE_ENV=&quot;production&quot;
</code></pre>
<p>Now I went to fire off the supervisor program via:</p>
<pre><code>sudo supervisorctl start hirerandybacon
</code></pre>
<p>And instead of a running app I received the following error message:</p>
<pre><code>hirerandybacon: ERROR (no such process) 
</code></pre>
<p>&quot;GRRR,&quot; said Randy.  This required more Google searching which brought me to this solution:</p>
<pre><code>supervisorctl reread
supervisorctl reload
</code></pre>
<p>FINALLY starting the program yields success and my site is now running.  Or is it?</p>
<h3 id="moreissues">More Issues</h3>
<p>I guess because I'm bored I decided to log into my blog and finish up my first post.  I tired to log in and received no response until a toast popped up saying a server error had occurred.</p>
<p>I checked the supervisor log and of course there where no relevant log items.  At this point I was tired and wanted to brutte force my way though this thing.  I decided to try to run the Node app again via the command line but this time as the www-data user (you know the user I assigned the app to above).  A quick change of the user via:</p>
<pre><code>sudo su www-data
</code></pre>
<p>Firing up the app via:</p>
<pre><code>NODE_ENV=production node app.js
</code></pre>
<p>And finally a useful error message.  The database was opening in read only mode.  Why?  Because when I deployed my database, although I thought I had chown'd the data directory and db to the :www-data group I hadn't changed permissions...  After changing the permissions on the data directory (775) and database (664) and restarting my app, I was in business.</p>
<p>After a few hours (or maybe an evening) my node app and blog is running in production.  I guess the plus side is I had another topic to blog about.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>