Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Node.js module for basic Twitter update_with_media support. You will need to install 'request' packages from npm like so: npm install request
fs = require('fs')
path = require('path')
request = require('request')
class twitter_update_with_media
constructor: (@auth_settings) ->
@api_url = ''
post: (status, file_path, callback) ->
r =, oauth:@auth_settings, callback)
form = r.form()
form.append('status', status)
form.append('media[]', fs.createReadStream(path.normalize(file_path)))
module.exports = twitter_update_with_media
// Generated by CoffeeScript 1.6.3
(function() {
var fs, path, request, twitter_update_with_media;
fs = require('fs');
path = require('path');
request = require('request');
twitter_update_with_media = (function() {
function twitter_update_with_media(auth_settings) {
this.auth_settings = auth_settings;
this.api_url = '';
} = function(status, file_path, callback) {
var form, r;
r =, {
oauth: this.auth_settings
}, callback);
form = r.form();
form.append('status', status);
return form.append('media[]', fs.createReadStream(path.normalize(file_path)));
return twitter_update_with_media;
module.exports = twitter_update_with_media;
twitter_update_with_media = require 'twitter_update_with_media'
tuwm = new twitter_update_with_media({
consumer_key: '...'
consumer_secret: '...'
token: '...'
token_secret: '...'
})'This is a test', '/path_to_image.png', (err, response) ->
console.log(err) if err
var twitter_update_with_media = require('twitter_update_with_media');
var tuwm = new twitter_update_with_media({
consumer_key: '...',
consumer_secret: '...',
token: '...',
token_secret: '...'
});'This is a test', '/path_to_image.png', function(err, response) {
if (err) {

This comment has been minimized.

Copy link

@chinna-muhil chinna-muhil commented Dec 30, 2013

It worked for me. BIG thanks much to you!!! :-)


This comment has been minimized.

Copy link

@neeravmakwana neeravmakwana commented Apr 18, 2014

Hi, I installed request module as suggested by you. Then I created the following 2 .js files in the folder C:\node_modules\request:

I updated the consumer key, secret etc. in usage.js and then ran usage.js from command prompt. I am getting the following error:

C:>node node_modules\request\usage.js

throw err;
Error: Cannot find module 'twitter_update_with_media'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (C:\node_modules\request\usage.js:1:95)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

Please note that I have created some basic bots which search for tweets and then retweet/reply and have these working satisfactorily (using twit module). However, I want to post media (use update with media) and couldn't figure out how to do it. So I installed request module, but can't seem to figure out how it works too.

Help will be appreciated.



This comment has been minimized.

Copy link

@michaelryancaputo michaelryancaputo commented Sep 30, 2014

Thank you for sharing this.


This comment has been minimized.

Copy link

@hawkfalcon hawkfalcon commented Jan 20, 2015

This is now deprecated for media/upload -> statuses/update (two separate POSTs)
Could you update this module for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment