title: Getting started with open source output: index.html theme: theme controls: false
-- intro
- Git & Github
- Branches, Pull Request
- What is NodeJS
- NPM packages and package.json
- Creating a node project
- A NodeJS webserver
- Testing
- Continuous Integration (CI)
--
A distributed version control system
--
A platform for collaborating on source code.
--
--
A JavaScript runtime to build scalable network applications
--
- currently hosts ~ 1m modules
- easy to use (
npm install <package>
) - easy to publish (
npm publish
) - use it with anything (folders, tarballs, git repositories)
- Attempt for JavaScript API standardization
Provides global module
, exports
and require()
to define this files API
// module1.js
exports.hello = 'World';
// or
module.exports = {
hello: 'World'
}
Using the module
// main.js
var mod1 = require('./module1');
console.log(mod1.hello); // -> World
--
CommonJS specification for describing JavaScript packages
{
"name": "nodeschool",
"version": "0.1.0",
"author": "Nodeschool <[email protected]>",
"description": "NodeJS FTW!",
"scripts": {
"test": "mocha test",
"start": "node lib/start.js"
},
"main": "./lib/main.js",
"repository": {
"type": "git", "url": "https://github.com/yycjs/node-up"
},
"dependencies": { "somePackage": "^1.0.0" },
"devDependencies": { "some-dev-only-package": "^0.2.0" },
"license": "MIT"
}
--
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
--
Split functionality into contained units. Ideally each function should perform one unit of work.
- Testing frameworks: Mocha, Jest, Jasmine, Ava
- Code quality tools
- ESLint
- Istanbul (code coverage)
- Codeclimate
--
- Use source control management system (SCM) for builds
- Run reports, tests, deploy or other tools on each SCM change
- Popular open source CI servers:
- Jenkins: Probably most popular CI server, formerly Hudson
- CruiseControl: CI framework initially by Thoughtworks
- Hosted CI services