How to use the async function of ES7 in node.js

  node.js, question

Entry file

require('babel-core/register');
 const app = require('./shiyan.js');

app.js

const http = require('http');
 async function ab() {
 await http.get('http://www.baidu.com/', (res) => {
 console.log('1');
 
 });
 
 console.log('2');
 bracket
 ab();
 
 console.log('3');

This is what I wrote, but it is wrong. The output is 3 2 1

My original intention was to export 1 2 3. I would like to ask the great god to tell me how to revise it. I am very grateful! ! !
Async function is used instead of consol.log (2) and console.log (3) in the callback function of end event.

I changed it, trying to “not write in the callback inside” according to your requirements, like this:

const http = require('http');
 async function ab() {
 //The key here is that await should be followed by a Promise
 await new Promise(function(resolve) {
 http.get('http://www.baidu.com/', (res) => {
 console.log('1');
 resolve();
 })
 });
 console.log('2');
 console.log('3');
 bracket
 ab();