Nearsighted Prank Master
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    inject-scriptpublic

    inject-script

    Inject a <script> node into a stream of HTML (right before the closing body tag) with a specified src.

    Usage

    stream.pipe(inject(src)).pipe(response)

    var inject = require('inject-script')
    var http = require('http')
    var path = require('path')
    var fs = require('fs')
     
    http.createServer(function (req, res) {
      if (req.url === '/script.js') {
        res.setHeader('content-type', 'application/json')
        fs.createReadStream(path.resolve(__dirname, 'script.js'))
          .pipe(res)
      } else {
        fs.createReadStream(path.resolve(__dirname, 'index.html'))
          .pipe(inject('/script.js'))
          .pipe(res)
      }
    }).listen(4242)

    License

    (The MIT License)

    Copyright 2014 Cameron Lakenen

    install

    npm i inject-script

    Downloadslast 7 days

    1

    version

    1.0.0

    license

    MIT

    repository

    github.com

    last publish

    collaborators

    • avatar