New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

snip

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snip

latest
npmnpm
Version
0.5.1
Version published
Maintainers
1
Created
Source

Snip

Snip is a ridiculously simple Node module to include client side files into other files (essentially the same as Server Side Includes with Apache). There might be, and probably are, other modules which include this functionality and a lot more - but I needed it for some demo code, was curious if I could get it to work in a couple hours as an experiment ... so here it is.

To install: fork or download this code and the "require" to the directory. Or you can npm install snip (this project is also my testing ground for NPM modules).

To use:

  • After installing, add "require('snip')"
  • Create a root level directory called "snips".
  • Place HTML in "snips" you want to include into other pages.
  • Place comments in the HTML you want to have the snips included in like this:
    <!-- snip:html/header.html -->
    While keeping the spacing the same as above, this comment would bring "header.html" from the "html" directory in "snips" to the page.
  • In where you are routing HTML, "snip" incoming data. Like so:
    <P>
    fs.readFile('views/index.html', 'utf8', function(err, data){<BR />
    	res.writeHead(200, {'Content-Type':'text/html'});  <BR />
    	res.write(snip.snip(data));  <BR />
    	res.end();<BR />
    	});<BR />
    </P>
    
    
    </LI>
    

That's it. Catch me on twitter @joshbirk if you have any questions.

Todo:

  • Make the "snips" directory controlled by environment variables.
  • Make snips multi-level.

FAQs

Package last updated on 17 Jan 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts