Skip to content

Instantly share code, notes, and snippets.

@SBejga
Last active February 27, 2017 16:02
Show Gist options
  • Save SBejga/5d1aaef02e45a25dddbf16ab0f174815 to your computer and use it in GitHub Desktop.
Save SBejga/5d1aaef02e45a25dddbf16ab0f174815 to your computer and use it in GitHub Desktop.
pwa-3 practice: read json file async with promises (typescript)
var fs = require('fs');
//npm install @types/node @types/es6-promise
function loadFromJson(filename: string) {
//TODO: read files async with Promises
}
var files: string[] = [
"good.json", "absent.json", "good2.json", "invalid.json", "good3.json"
];
//TODO:
// Read Files in order of array and abort if error occurs
// Hints:
// fs.readFile(file: str, (err, data) => {})
// JSON.parse(str): any
{"message": "first file"}
{"message": "second file"}
{"message": "third file"}
{invalid: json}
{
"name": "fspromise",
"version": "1.0.0",
"description": "",
"main": "build/js/fsPromise.js",
"scripts": {
"demo": "tsc && node build/js/fsPromise.js",
"setGist": "gist -o -u 5d1aaef02e45a25dddbf16ab0f174815 fsPromise.ts package.json tsconfig.json good.json good2.json good3.json invalid.json .gitignore"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^6.0.45",
"@types/es6-promise": "0.0.32"
}
}
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"removeComments": true,
"typeRoots": [
"node_modules/@types"
],
"outDir": "build/js",
"inlineSourceMap": true
},
"exclude": [
"node_modules"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment