我正在研究twit API。我的代码在本地(节点bot.js)工作得非常好但是当我将我的文件上传到Heroku时它不工作。它说模块" twit"未找到 ! 这是我的代码:
console.log("Bot is running !");
const Twit = require("twit");
const config = require("./config");
const twit = new Twit(config);
const stream = twit.stream("user");
const operation = {
"doTwit" : msg => {
twit.post('statuses/update',
{ status: msg },
(err, data, response) => {
if (err) {
console.log("An Error Occured !" + err.message);
} else {
console.log("Successfully tweeted !");
}
});
},
"sendMessage" : (id, name, msg) => {
twit.post(
"direct_messages/new",
{
user_id : id,
screen_name : name,
text : msg
},
(err, data, res) => {
if (err) {
operation.sendMessage(807594238535868421, "designer_sohail", err.message);
console.log("An Error Occured !" + err.message);
}
}
);
}
}
stream.on("follow", e => {
operation.sendMessage(e.source.id, e.source.screen_name, `Thanks for
following me. How are you ${e.source.screen_name}!`);
});
stream.on('favorite', e => {
operation.sendMessage(e.source.id, e.source.screen_name, `Thanks for favouriting my tweet! ${e.target_object.text.slice(0,25)} ...`);
})
在我的Procfile里面,我把#34; worker:node bot.js" 在我的配置文件中
module.exports = {
consumer_key: "values",
consumer_secret: "values",
access_token: "values",
access_token_secret: "values"
}
这些是来自Heroku的构建日志 我点击了最新版本并从那里复制 :
Node.js app detected
Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 8.x...
Downloading and installing node 8.9.4...
Using default npm version: 5.6.0
Restoring cache
Loading 2 from cacheDirectories (default):
- node_modules (exists - skipping)
- bower_components (not cached - skipping)
Building dependencies
Prebuild detected (node_modules already exists)
Rebuilding any native modules
ajv@5.5.2 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/ajv
co@4.6.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/co
fast-deep-equal@1.0.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/fast-deep-equal
fast-json-stable-stringify@2.0.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/fast-json-stable-stringify
json-schema-traverse@0.3.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/json-schema-traverse
asn1@0.2.3 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/asn1
assert-plus@1.0.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/assert-plus
asynckit@0.4.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/asynckit
aws-sign2@0.7.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/aws-sign2
aws4@1.6.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/aws4
bcrypt-pbkdf@1.0.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/bcrypt-pbkdf
tweetnacl@0.14.5 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/tweetnacl
bluebird@3.5.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/bluebird
boom@4.3.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/boom
hoek@4.2.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/hoek
caseless@0.12.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/caseless
combined-stream@1.0.5 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/combined-stream
delayed-stream@1.0.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/delayed-stream
core-util-is@1.0.2 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/core-util-is
dashdash@1.14.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/dashdash
ecc-jsbn@0.1.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/ecc-jsbn
jsbn@0.1.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/jsbn
extend@3.0.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/extend
extsprintf@1.3.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/extsprintf
forever-agent@0.6.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/forever-agent
form-data@2.3.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/form-data
mime-types@2.1.17 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/mime-types
mime-db@1.30.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/mime-db
getpass@0.1.7 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/getpass
har-schema@2.0.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/har-schema
har-validator@5.0.3 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/har-validator
hawk@6.0.2 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/hawk
cryptiles@3.1.2 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/cryptiles
boom@5.2.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/cryptiles/node_modules/boom
sntp@2.1.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/sntp
http-signature@1.2.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/http-signature
jsprim@1.4.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/jsprim
json-schema@0.2.3 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/json-schema
verror@1.10.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/verror
sshpk@1.13.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/sshpk
is-typedarray@1.0.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/is-typedarray
isstream@0.1.2 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/isstream
json-stringify-safe@5.0.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/json-stringify-safe
oauth-sign@0.8.2 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/oauth-sign
performance-now@2.1.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/performance-now
punycode@1.4.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/punycode
qs@6.5.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/qs
request@2.83.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/request
safe-buffer@5.1.1 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/safe-buffer
stringstream@0.0.5 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/stringstream
tough-cookie@2.3.3 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/tough-cookie
tunnel-agent@0.6.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/tunnel-agent
uuid@3.1.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/uuid
twit@2.2.9 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/twit
mime@1.6.0 /tmp/build_2fd6e2dc3b700b830abe821f30d7c86b/node_modules/mime
Installing any new modules (package.json)
removed 55 packages in 0.632s
Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- node_modules
- bower_components (nothing to cache)
Build succeeded!
Discovering process types
Procfile declares types -> worker
Default types for buildpack -> web
Compressing...
Done: 17.3M
Launching...
Released v10
https://twitter-bot-sohail.herokuapp.com/ deployed to Heroku