Using ES6 with gulp — Mark Goodyear — Front-end developer and designer

Jun 24, 2015

With gulp 3.9, we are now able to use ES6 (or ES2015 as it’s now named) in our gulpfile—thanks to the awesome Babel transpiler.

Firstly make sure you have at least version 3.9 of both the CLI and local version of gulp. To check which version you have, open up terminal and type:

gulp -v

This should return:

CLI version 3.9.0
Local version 3.9.0

If you get any versions lower than 3.9, update gulp in your package.json file, and run the following to update both versions:

npm install gulp && npm install gulp -g

Creating an ES6 gulpfile

To leverage ES6 you will need to install Babel (make sure you have Babel 6) as a dependency to your project, along with the es2015 plugin preset:

npm install babel-core babel-preset-es2015 --save-dev

Once this has finished, we need to create a .babelrc config file to enable the es2015 preset:

touch .babelrc

And add the following to the file:

  "presets": ["es2015"]

We then need to instruct gulp to use Babel. To do this, we need to rename the gulpfile.js to gulpfile.babel.js:

mv "gulpfile.js" "gulpfile.babel.js"

We can now use ES6 via Babel! An example of a typical gulp task using new ES6 features:

'use strict';

import gulp from 'gulp';
import sass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import sourcemaps from 'gulp-sourcemaps';

const dirs = {
  src: 'src',
  dest: 'build'

const sassPaths = {
  src: `${dirs.src}/app.scss`,
  dest: `${dirs.dest}/styles/`

gulp.task('styles', () => {
  return gulp.src(paths.src)
    .pipe(sass.sync().on('error', plugins.sass.logError))

Here we have utilised ES6 import/modules, arrow functions, template strings and constants. If you’d like to check out more ES6 features, is a handy resource.

分类: 未分类 | 308 个字 | 评论

Node.js Application as a Windows Service (With registry fix) – Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

npm install

In my case, command nssm install MyWebService… was unsuccessful, the problem was that app.js can’t find config.json file.

First you will need:

  1. Node.js application (project) which you want to run as a Windows Service
  2. Node.js
  3. NSSM

1 step: Set your Node.js application as Windows Service

Download nssm.exe and put file into you node.js project folder

Put nssm.exe file into you node.js project folder

Run Windows Command Processor (cmd.exe) as administrator and go to your node.js project folder

Your node.js project folder

Run command npm install

npm install

Run command node src\app.js and allow access through Windows firewall

Allow access through Windows firewall

Run these two commands
nssm.exe install MyWebService "C:\Program Files\nodejs\node.exe" "C:\Service\src\app.js"
net start MyWebService

net start MyWebService

Now we need to fix this error.

2 step: Edit registry

Open registry editor (regedit.exe) and go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MyWebService\Parameters


Now we need to change AppDirectory from C:\Program Files\nodejs to C:\Service

Change AppDirectory from C:\Program Files\nodejs to C:\Service

Restart computer and don’t forget to run Apache, MySQL or any other necessary servers for your project after restart.

Node.js Application as a Windows Service


package.json 里的依赖怎么写


{ “dependencies” :
{ “foo” : “1.0.0 – 2.9999.9999”
, “bar” : “>=1.0.2 <2.1.2”
, “baz” : “>1.0.2 <=2.3.4”
, “boo” : “2.0.1”
, “qux” : “<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0”
, “asd” : “”
, “til” : “~1.2”
, “elf” : “~1.2.3”
, “two” : “2.x”
, “thr” : “3.3.x”

version 完全匹配

version 大于这个版本
=version1 <=version2.
range1 || range2 满足任意一个即可
git… Git地址





d3 时间格式

%a – abbreviated weekday name.
%A – full weekday name.
%b – abbreviated month name.
%B – full month name.
%c – date and time, as “%a %b %e %H:%M:%S %Y”.
%d – zero-padded day of the month as a decimal number [01,31].
%e – space-padded day of the month as a decimal number [ 1,31]; equivalent to %_d.
%H – hour (24-hour clock) as a decimal number [00,23].
%I – hour (12-hour clock) as a decimal number [01,12].
%j – day of the year as a decimal number [001,366].
%m – month as a decimal number [01,12].
%M – minute as a decimal number [00,59].
%L – milliseconds as a decimal number [000, 999].
%p – either AM or PM.
%S – second as a decimal number [00,61].
%U – week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
%w – weekday as a decimal number [0(Sunday),6].
%W – week number of the year (Monday as the first day of the week) as a decimal number [00,53].
%x – date, as “%m/%d/%Y”.
%X – time, as “%H:%M:%S”.
%y – year without century as a decimal number [00,99].
%Y – year with century as a decimal number.
%Z – time zone offset, such as “-0700”.
%% – a literal “%” character.

分类: 未分类 | 210 个字 | 评论