22
33### Getting Started
44
5- First we'll install ` babel- cli ` and ` babel- preset-env ` .
5+ First we'll install ` @ babel/ cli` , ` @babel/core ` and ` @ babel/ preset-env` .
66
77``` shell
8- $ npm install --save-dev babel- cli babel- preset-env
8+ $ npm install --save-dev @ babel/ cli @ babel/core @babel/ preset-env
99```
1010
1111Then we'll create a ` .babelrc ` file for configuring babel.
@@ -18,7 +18,7 @@ This will host any options we might want to configure `babel` with.
1818
1919``` json
2020{
21- "presets" : [" env" ]
21+ "presets" : [" @babel/preset- env" ]
2222}
2323```
2424
@@ -30,12 +30,14 @@ $ touch index.js
3030``` js
3131import http from ' http' ;
3232
33- http .createServer ((req , res ) => {
33+ const server = http .createServer ((req , res ) => {
3434 res .writeHead (200 , {' Content-Type' : ' text/plain' });
3535 res .end (' Hello World\n ' );
3636}).listen (1337 , ' 127.0.0.1' );
3737
3838console .log (' Server running at http://127.0.0.1:1337/' );
39+
40+ export default server ;
3941```
4042
4143With recent changes to babel, you will need to transpile your ES6 before node can run it.
@@ -171,22 +173,23 @@ $ touch test/index.js
171173import http from ' http' ;
172174import assert from ' assert' ;
173175
174- import ' ../lib/index.js' ;
176+ import server from ' ../lib/index.js' ;
175177
176178describe (' Example Node Server' , () => {
177179 it (' should return 200' , done => {
178180 http .get (' http://127.0.0.1:1337' , res => {
179181 assert .equal (200 , res .statusCode );
182+ server .close ();
180183 done ();
181184 });
182185 });
183186});
184187```
185188
186- Next, install ` babel- register ` for the require hook.
189+ Next, install ` @ babel/ register` for the require hook.
187190
188191``` shell
189- $ npm install --save-dev babel- register
192+ $ npm install --save-dev @ babel/ register
190193```
191194
192195Then we can add an ` npm test ` script.
@@ -196,7 +199,7 @@ Then we can add an `npm test` script.
196199 "start": "nodemon lib/index.js --exec babel-node",
197200 "build": "babel lib -d dist",
198201 "serve": "node dist/index.js",
199- + "test": "mocha --require babel- register"
202+ + "test": "mocha --require @ babel/ register"
200203 }
201204```
202205
0 commit comments