Skip to content

Instantly share code, notes, and snippets.

var fs = require('fs');
var util = require('util');
var writer = fs.createWriteStream('../log.txt');
fs.watch('.', function (event, filename) {
writer.write('================\nEvent: ' + event + '\n');
if (filename) {
@gld1982ltd
gld1982ltd / gist:d0d7ac835011d1f9bef2
Created January 29, 2016 03:33 — forked from yuanchuan/gist:2586540
Watch a directory recursively
/**
* Watch a directory recursively
*
* @param {String} dir
* @param {Function} cb
*
* watchRecursive('directory', function(current) {
* console.log(current, ' changed');
* });
*/
@gld1982ltd
gld1982ltd / combinejs.js
Created January 29, 2016 03:19 — forked from dobesv/combinejs.js
Combine, minify, and compress javascript files. Supports "watching" the files for automatic updates
#!node
var fs = require('fs'),
path = require('path'),
gzip = require('./gzip');
function process(fileBody, options, cb) {
if(typeof(fileBody) === 'object') {
options = fileBody;
fileBody = undefined;
cb = options;
@gld1982ltd
gld1982ltd / gist:112015db2ed16b957fb7
Created January 23, 2016 18:23 — forked from Gomah/gist:7364945
Static webserver @node.js
// Variables dc (http://nodejs.org/api/)
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
port = process.argv[2] || 1337, // Array ex -> http://nodejs.org/docs/latest/api/process.html#process_process_argv
mimeTypes = {
// Basic mimes
'asc' : 'text/plain',
// Restify Server CheatSheet.
// More about the API: http://mcavage.me/node-restify/#server-api
// Install restify with npm install restify
// 1.1. Creating a Server.
// http://mcavage.me/node-restify/#Creating-a-Server
var restify = require('restify');
@gld1982ltd
gld1982ltd / simple-mms-server.js
Created January 23, 2016 17:44 — forked from vitapluvia/simple-mms-server.js
MMA CTF 2015 - Stream... Single File Server
m=require; m('http').createServer(function(_, r) {r.end(m('fs').readFileSync("extracted"))}).listen(4444);
@gld1982ltd
gld1982ltd / server.js
Created January 22, 2016 18:51 — forked from iuliaL/server.js
node http.createServer
// node server instead of xampp ;
var http = require('http');
var fs = require('fs');
http.createServer(function (request, response) {
var filePath = '.' + request.url;
console.log(request.url);
fs.readFile(filePath, function(error, content) {
response.writeHead(200);
@gld1982ltd
gld1982ltd / server.js
Last active January 20, 2016 04:25 — forked from nariatan/server.js
Simple node.js server (livereload)
/*
* 1) run node server.js in root category where installed node
* 2) install browser extention
* 3) http://localhost:3000/index.html
*/
//server settings
var serveStatic = require('serve-static');
var connect = require('connect');
var http = require('http');
@gld1982ltd
gld1982ltd / static_server.js
Created January 19, 2016 13:37 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
@gld1982ltd
gld1982ltd / npm-boilerplate-package.json
Created January 16, 2016 07:19 — forked from iksi/npm-boilerplate-package.json
npm boilerplate package for web projects
{
"name": "project",
"private": true,
"scripts": {
"build:css": "postcss --use postcss-import --use autoprefixer --autoprefixer.browsers 'last 3 versions' --use cssnano --use postcss-cssnext --output assets/css/full.css assets/css/src/index.css",
"watch:css": "postcss --watch --use postcss-import --use autoprefixer --autoprefixer.browsers 'last 3 versions' --use cssnano --use postcss-cssnext --output assets/css/full.css assets/css/src/index.css",
"build:js": "uglifyjs assets/js/src/init.js --no-mangle --compress sequences=true,dead_code=true,conditionals=true,booleans=true,unused=true,if_return=true,join_vars=true,drop_console=true --output assets/js/full.js",
"watch:js": "watch 'uglifyjs assets/js/src/init.js --no-mangle --source-map full.js.map --output assets/js/full.js' assets/js/src"
},
"devDependencies": {