Simple promise demo

Just saw one article about JS promise + async/await 
the example for promise is like :

const posts = [
{ title: 'Post 1', content: 'fake content'},
{ title: 'Post 2', content: 'fake content'},
];
const getPosts = () => new Promise(resolve => setTimeout(() => resolve(posts), 1000));
const printPostsToConsole = () => getPosts().then(posts => console.log(posts));
printPostsToConsole();
console.log('hello world'); // let me add one more line in
The result would be : 
hello world
[{ title: 'Post 1', content: 'fake content'},
{ title: 'Post 2', content: 'fake content'}]
Very simple process but still have something we can notice: 
1. 'hello world' would present before the Prmise-then function
2. In node7, code have to dealing 'reject' situation otherwise node will terminated process with exit(0)
As a result, the complete code should be : 
const getPosts = () => new Promise(
(resolve, reject) => {
if(posts){
setTimeout(() => resolve(posts), 1000)
}
else {
reject()
});
and
const printPostsToConsole = () => getPosts().then(posts => console.log(posts)).catch((err) => console.error(err));
Cheers~~