Archive: 2013

0

npm tips and tricks

In my previous post I showed you how easily you can create a simple webserver using Node.js. In this post I want to show you how to make more advanced usage of node package manager. npm initUsing node package manager you can get an even quicker start of your project by using the npm init command. So let’s get started by opening a command prompt (on windows open the Node.js command prompt). Then create a new folder and navigate into this newly created folder. In the folder execute following command and answer the questions or press enter for the defaults. 1234567891011121314151617181920212223242526272829303132333435363738394041424344Your environment has been set up for using Node.js 0.10.17 (x64) and npm.Press any key to continue . . .C:\Users\Marco> mkdir NodeJsPackageExampleC:\Users\Marco> cd NodeJsPackageExampleC:\Users\Marco\NodeJsPackageExample> npm initThis utility will walk you through creating a package.json file.It only covers the most common items, and tries to guess sane defaults.See `npm help json` for definitive documentation on these fieldsand exactly what they do.Use `npm install --save` afterwards to install a package andsave it as a dependency in the package.json file.Press ^C at any time to quit.name: (NodeJsPackageExample) node-js-package-exampleversion: (0.0.0) 0.0.1description: Total package awesomenessentry point: (index.js)test command:git repository:keywords: package, awesomenessauthor: Marco Franssenlicense: (BSD-2-Clause) MITAbout to write to C:\Users\Marco\NodeJsPackageExample\package.json:{ "name": "node-js-package-example", "version": "0.0.1", "description": "Total package awesomeness", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ "package", "awesomeness" ], "author": "Marco Franssen", "license": "MIT"}Is this ok? (yes) yes After answering the questions the result should be something like above. As you can see I have changed the default name. By default node package manager uses the folder name. Play around yourself to get the desired result. You can also change the package.json after it is created. Why do we need this package.json file?

0

Starting with a Node.js webserver

Before starting to explain how you start your first Node.js project for building a simple web server I will first explain you what Node.js is. To do so I just include a quote of the Node.js themself, because I don’t like to reinvent the wheel. Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. The next thing you should know is about the Node.js Package Manager (NPM). Using NPM you can benefit from the thousands of open source packages so you won’t have to build everything yourself. I suppose you already have installed Node.js. Let’s start with a simple Hello World in Node.js by creating a file called hello-world.js and execute our script to show the result. hello-world.js1console.log('Hello World'); We can execute the script using following command. (On Windows open the Node.js command prompt) Navigate to your folder containing the just created hello-world.js file and execute the script using node. 123456Your environment has been set up for using Node.js 4.1.1 (x64) and npm.Press any key to continue . . .C:\Users\Marco> cd MyHelloWorldCodeFolderC:\Users\Marco\MyHelloWorldCodeFolder> node hello-world.jsHello World

0

CI with Jenkins, MSBuild, Nuget and Git part 4

In part 1, 2 and 3 I showed you how to create a simple MSBuild script and how to execute it from the command line. We had a look at how to clean your output directories, download the Nuget packages, compile your code, run MSpec tests and creating a code coverage report. In this last part of this series I will show you how to integrate it with Jenkins. First of all we want Jenkins to pull the latest code from Github as soon as somebody has pushed new code to Github. To do this we need to install the Github plugin in Jenkins. We will also install the “MSBuild plugin” in Jenkins to be able to use MSBuild in Jenkins and the “Html publisher plugin” to publish the Coverage and MSpec reports. Also install the “Jenkins Git plugin” to configure the repository in Jenkins.

0

CI with Jenkins, MSBuild, Nuget and Git part 3

In the previous parts (part 1, part 2) of this series I described how to clean, download Nuget packages and build your solution using MSBuild. In this part I will explain you how to create a MSpec MSBuild target and a Code coverage MSBuild target. MSpec is a testing framework which enables you to write living specifications. Using the MSpec console runner you can easily generate an html report. This report can later on be published using the Jenkins report plugin. By publishing this report we have some documentation on the specifications of the software available and because we did write the specifications using MSpec we also have unit tests in place. So that’s why I call it living documentation. :D For generating the code coverage report we use the xml output of our MSpec tests. These reports will also be published using the Jenkins report plugin. To do so I use OpenCover and ReportGenerator. All three packages are installed in my solution using Nuget. So the paths in my build script are based on the paths of my source/packages folders.

0

CI with Jenkins, MSBuild, Nuget and Git part 2

In part 1 of this blog series we had a look at a very basic MSBuild script which enables us to compile our projects. For doing this I provided you guys with a simple batch file to make it even more simple to execute the build script. In this episode we will focus on cleaning the folders before building again and getting the Nuget packages using Nuget package restore. The latter I will explain further for you first. Nuget package restore can be enabled in Visual studio. A best practice is to enable this always, because then we won’t have to put all Nuget packages in source control. By enabling it, every team member will download the missing packages automatically when building his project in Visual Studio. However the build server won’t do this by default so we create a custom target in our build script to make this happen.

0

CI with Jenkins, MSBuild, Nuget and Git part 1

Very lately I have worked on setting up some continuous integration (CI) using MSbuild for my c# project. In this blog series I will explain to you how to set up continuous integration. First of all we will start with creating a MSBuild script which will compile our code. We will also create a small batch file for easy executing the MSbuild script. When that is in place, we will add several targets to the build script to run for example unit tests, integration tests, code coverage, packaging etc. So we will take the agile approach and improve our build process based on validated learning. First of all we need some basic knowledge about MSbuild. I think there are enough pages around on the web which will give you a basic introduction. A good starting point would be the MSDN documentation for MSBuild. Let’s consider we have the following project structure within our Git repository / local file system. src (contains our source code) lib (contains build output, and third party libs not available on nuget) reports (contains code coverage reports, test scenarios and test results) ci.msbuild (your msbuildfile) ci.msbuild.cmd (your batch file to execute the build on your local machine)