You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a. http
- Setting up a server
var http = require('http');
var server = http.createServer();
server.on('request', function (req, res) {
res.send(...);
});
server.listen(3000);
console.log('Server listening on port 3000');
OR
var http = require('http');
var server = http.createServer(function (req, res) {
res.send(...);
}).listen(3000);
console.log('Server listening on port 3000');
b. qs
- qs == querystring
-
c. url
d. fs
e. cluster (multithreading)
f. crypto
g. net
h. modules
i. path
j.
Modules (third party)
a. node-debug
b. express
-
- Production Mode
NODE_DEV=production node app.js
c. async
- map:
arg1 - an array of data
arg2 - this is an iterator function that takes an item and callback,
arg3 - callback(err, results) function that calls the callback
Example:
var myTestFunction = function (item, callback) {
var x = item + ' added something.';
console.log(x);
};
async.map(['file1','file2','file3'], myTestFunction, function(err, results){ callback(results) });
d. request
e.
Create an index.js that requires the lib/*.js file
- module.exports = require('./lib/<MyModule>.js');
Go to the project you want to install the module in and add this line to package.json (in dependencies object):
- "project_name": "git+ssh://[email protected]:project_name"
Make sure private is true in package.json
$ npm install
require the module in your project
- i.e. var md = require('myModule');
Adding to your package.json
npm install --save NOTE: you can make an alias that does this for you.
npm install --save-dev NOTE: this will add the module to your package.json's devDependencies object