Grunt task to get a free port number on localhost from specified range. Uses node-portscanner.
$ npm i -S grunt-freeport
grunt.initConfig({
freeport: {
sometask: {
options: {
start: 8080,
end: 8089
}
}
},
sometask: {
options: {
port: '<%= freeport.sometask %>'
}
}
});
// common, start using `load-grunt-tasks`
grunt.loadNpmTasks('grunt-freeport');
grunt.registerTask('default', [ 'freeport:sometask', 'sometask' ]);
start
– start point to find a free port, must be>= 1
,1
by defaultend
– end point to find a free port, must be<= 65535
,65535
by default
If task target is omitted then it will use default variable name freeport
, i.e. you should use '<%= freeport %>'
.