console.log('Hello world');
npm init
{
"name": "my-package",
"version": "1.0.0",
"description": "This is just description of my awesome package",
"main": "index.js",
"scripts": {
"dev": "nodemon --exec npm run start",
"start": "tsc && node dist/index.js",
"test": "mocha --opts mocha.opts"
},
"author": "Martin Nuc",
"license": "ISC",
"dependencies": {
"@types/chai": "4.0.4",
"@types/mocha": "2.2.43",
"@types/node": "8.0.28",
"@types/sinon": "2.3.4",
"chai": "4.1.2",
"mocha": "3.5.3",
"nodemon": "1.12.1",
"sinon": "3.2.1",
"ts-node": "3.3.0",
"typescript": "2.5.2"
}
}
package.json
npm
npm install lodash
installs lodash library:
const _ = require('lodash');
const words = _.words('Hello, how are you?');
// ['Hello', 'how', 'are', 'you']
console.log(words);
{
"name": "my-package",
"version": "1.0.0",
"description": "This is just description of my awesome package",
"main": "index.js",
"scripts": {
"dev": "nodemon --exec npm run start",
"start": "tsc && node dist/index.js",
"test": "mocha --opts mocha.opts"
},
"author": "Martin Nuc",
"license": "ISC",
"dependencies": {
"@types/chai": "4.0.4",
"@types/mocha": "2.2.43",
"@types/node": "8.0.28",
"@types/sinon": "2.3.4",
"lodash": "4.17.5",
"chai": "4.1.2",
"mocha": "3.5.3",
"nodemon": "1.12.1",
"sinon": "3.2.1",
"ts-node": "3.3.0",
"typescript": "2.5.2"
}
}
package.json
6.11.2
patch
minor version
major version
6.11.2
patch
minor version
major version
- major changes, breaks API
6.11.2
patch
minor version
- new features
- doesn't break API
major version
- major changes, breaks API
6.11.2
patch
- only bugfixes
minor version
- new features
- doesn't break API
major version
- major changes, breaks API
"scripts": {
"dev": "nodemon --exec npm run start",
"start": "node index.js",
"test": "mocha --opts mocha.opts"
},
Shortcut for start and test scripts only. For others you have to use npm run
Runs any script from npm.
👉
const fs = require('fs');
fs.writeFileSync('file.txt', 'Hello');
const fs = require('fs');
let content;
content = fs.readFileSync('file.txt', 'utf8');
const fs = require('fs');
fs.readFile('file.txt', 'utf8', (err, content) => {
console.log('reading done', content);
});
function write(filename, content) {...}
function read(filename) {...}
index.js:2 const searchedString = 'devDependencies';
package.json:11 "devDependencies": {
Hints:
- look in documentation for fs.readdir()
- look in docs for fs.stat()
Output when searching for "devDependencies":