Permalink
Browse files

NodeJS snippets from https://github.com/jamescarr/snipmate-nodejs

  • Loading branch information...
1 parent f32ce2d commit 65506394942fb579c5bb3561add06f3ae04abf16 @lfilho lfilho committed May 12, 2012
Showing with 119 additions and 0 deletions.
  1. +3 −0 javascript/addLis.snippet
  2. +3 −0 javascript/app.get.snippet
  3. +3 −0 javascript/app.listen.snippet
  4. +3 −0 javascript/app.post.snippet
  5. +1 −0 javascript/assert.notE.snippet
  6. +1 −0 javascript/assertdeep.snippet
  7. +1 −0 javascript/asserteq.snippet
  8. +1 −0 javascript/crypto.createCred.snippet
  9. +1 −0 javascript/env.snippet
  10. +18 −0 javascript/express.snippet
  11. +3 −0 javascript/filt.snippet
  12. +3 −0 javascript/foreEach.snippet
  13. +3 −0 javascript/fs.readFile.snippet
  14. +3 −0 javascript/fs.unlink.snippet
  15. +2 −0 javascript/fs.watchFile.snippet
  16. +3 −0 javascript/fs.writeFile.snippet
  17. +1 −0 javascript/func.snippet
  18. +1 −0 javascript/http.createClient.snippet
  19. +3 −0 javascript/http.createServer.snippet
  20. +1 −0 javascript/json.pa.snippet
  21. +1 −0 javascript/json.st.snippet
  22. +1 −0 javascript/mongoose.connect.snippet
  23. +3 −0 javascript/mongoose.find.snippet
  24. +7 −0 javascript/mongoose.model.snippet
  25. +8 −0 javascript/net.createServer.snippet
  26. +3 −0 javascript/on.snippet
  27. +2 −0 javascript/req.snippet
  28. +2 −0 javascript/reqfs.snippet
  29. +2 −0 javascript/reqhttp.snippet
  30. +1 −0 javascript/reqio.snippet
  31. +1 −0 javascript/reqmongoose.snippet
  32. +1 −0 javascript/reqpath.snippet
  33. +1 −0 javascript/reqsys.snippet
  34. +9 −0 javascript/reqvows.snippet
  35. +5 −0 javascript/res.render.snippet
  36. +1 −0 javascript/setinterv.snippet
  37. +1 −0 javascript/settime.snippet
  38. +1 −0 javascript/sysi.snippet
  39. +10 −0 javascript/websocket.snippet
  40. +1 −0 javascript/writeHead.snippet
@@ -0,0 +1,3 @@
+addListener('${1:event}', function(${2:}){
+ ${3:}
+});
@@ -0,0 +1,3 @@
+app.get('${1:path}', function(req, res, next){
+ ${2:}
+});
@@ -0,0 +1,3 @@
+app.listen(${1:3000}, ${2:function(){
+ console.log("App server listening on port %d", app.address().port);
+}});
@@ -0,0 +1,3 @@
+app.post('${1:path}', function(req, res, next){
+ ${2:}
+});
@@ -0,0 +1 @@
+assert.notEqual(${1:actual}, ${2:expected});
@@ -0,0 +1 @@
+assert.deepEqual(${1:actual}, ${2:expected});
@@ -0,0 +1 @@
+assert.equal(${1:actual}, ${2:expected});
@@ -0,0 +1 @@
+crypto.createCredentials({key:${1:key}, cert:${2:cert}${3:, ca:[]});
View
@@ -0,0 +1 @@
+process.env.${1:VARIABLE}
View
@@ -0,0 +1,18 @@
+var app = express.createServer();
+
+app.configure(function(){
+ app.set('views', __dirname + '${1:/../views}');
+ ${2:app.use(connect.bodyDecoder());}
+ ${3:app.use(connect.methodOverride());}
+ app.use(connect.compiler({ src: __dirname + '/../public', enable: ['less'] }));
+ app.use(app.router);
+ app.use(connect.staticProvider(__dirname + '${4:/../public'}));
+});
+
+app.configure('development', function(){
+ app.use(connect.errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
+app.configure('production', function(){
+ app.use(connect.errorHandler());
+});
View
@@ -0,0 +1,3 @@
+filter(function(item){
+ return ${1:false};
+});
@@ -0,0 +1,3 @@
+forEach(function(${1:item},${2:index}){
+ ${3:}
+});
@@ -0,0 +1,3 @@
+fs.readFile('${1:filename}', function(err, data){
+ ${2: }
+});
@@ -0,0 +1,3 @@
+fs.unlink('${1:location}', function(err){
+ ${2: }
+});
@@ -0,0 +1,2 @@
+fs.watchFile('${1:filename}', function(current, previous){
+});
@@ -0,0 +1,3 @@
+fs.writeFile('${1:filename}', ${2:data}, ${3:'utf8'}, function(err){
+ ${4: }
+});
View
@@ -0,0 +1 @@
+function(${1:}){${2:}}
@@ -0,0 +1 @@
+http.createClient(${1:80}, '${2:www.google.com}');
@@ -0,0 +1,3 @@
+http.createServer(function(${1:request}, ${2:response}){
+ ${3:}
+}).listen(${4:8124});
@@ -0,0 +1 @@
+JSON.parse(${1:'{"string":"of json"}});
@@ -0,0 +1 @@
+JSON.stringify(${1:{some:'object'}});
@@ -0,0 +1 @@
+mongoose.connect('mongodb://${1:localhost}/${2:collection}');
@@ -0,0 +1,3 @@
+${1:Model}.find({ ${2:} }).all(function(${3:results}){
+ ${4:}
+});
@@ -0,0 +1,7 @@
+mongoose.model('${1:Model}', {
+ properties: [
+ ${2:'name'}
+ ],
+ indexes: [ ${3:'name'} ],
+ cast: { ${4:} }
+});
@@ -0,0 +1,8 @@
+net.createServer(function(${1:socket}){
+ $1.setEncoding("${2:utf8}");
+ $1.on('data', function(data){
+ });
+ $1.on('end', function(){
+
+ });
+}).listen(${3:8124}, '${4:127.0.0.1}');
View
@@ -0,0 +1,3 @@
+on('${1:eventname}', function(${2:err, res}){
+ ${3:}
+});
View
@@ -0,0 +1,2 @@
+var $1 = require ('${1:sys}')
+
View
@@ -0,0 +1,2 @@
+var fs = require('fs');
+
@@ -0,0 +1,2 @@
+var http = require('http');
+
View
@@ -0,0 +1 @@
+var io = require('socketio');
@@ -0,0 +1 @@
+var mongoose = require('mongoose').Mongoose;
@@ -0,0 +1 @@
+require.paths.unshift(${1:__dirname}${2:+'/lib/'});
@@ -0,0 +1 @@
+var sys = require('sys');
@@ -0,0 +1,9 @@
+var vows = require('vows');
+var assert = require('assert');
+
+vows.describe('${1:something}').addBatch({
+ '${2:firstthing}':{
+ topic:function(){
+ }
+ }
+}).export(module);
@@ -0,0 +1,5 @@
+res.render('${1:template}', {
+ locals:{
+ ${2:templatevars}
+ }
+});
@@ -0,0 +1 @@
+setInterval(${1:callback}, ${2:delay})
@@ -0,0 +1 @@
+setTimeout(${1:operation}, ${2:miliseconds})
View
@@ -0,0 +1 @@
+sys.inspect(${1:object})
@@ -0,0 +1,10 @@
+var ${1:socket} = ${2:io}.listen(${3:app});
+
+$1.on('connection', function(client){
+ client.on('message', function(${4:msg}){
+ ${5:}
+ });
+ client.on('disconnect', function(){
+ ${6:}
+ });
+});
@@ -0,0 +1 @@
+writeHead(${1:200}, ${2:{'Content-Type':'text/plain'}});

0 comments on commit 6550639

Please sign in to comment.