为什么我的Javascript文件没有运行?

时间:2017-10-04 02:24:55

标签: javascript node.js reddit

  "name": "javascript-development-environment",
  "version": "1.0.0",
  "description": "CS 235 package.json file for programming projects",
  "scripts": {
    "prestart": "babel-node buildScripts/startMessage.js",
    "redditImgGet": "babel-node buildScripts/srcReddit.js",
    "install": "npm install",
    "start":"npm-run-all --parallel security-check open:src",
    "security-check": "nsp check",
    "open:src": "babel-node buildScripts/srcServer.js"
  },

目前我是package.json。我试图调用从 reddit 获取图像的脚本。 srcReddit.js的内部如下所示:

var snoowrap = require('snoowrap');

console.log("Starting Reddit Image Fetcher");

const otherRequester = new snoowrap({
    userAgent: navigator.userAgent,
    clientId: 'Cf8kGqDSuT17xw',
    clientSecret: 'DDmMslUwMJW1ZM5JTc07zJDpC8k',
    username: 'sharan100',
    password: 'Magewindu100'
});

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

r.getHot().map(post => post.title).then(console.log);

console.log("Ending Reddit Image Fetcher");

为此,我使用了snoowrap的包装器reddit API。现在当我做npm start时,我出于某种原因得到以下结果:

enter image description here

不知道为什么console.log消息没有出现。有谁知道为什么?

1 个答案:

答案 0 :(得分:1)

npm start运行start任务,它似乎在任何时候都没有引用redditImgGet任务。

我认为您应该将start任务更改为

npm-run-all --parallel security-check open:src redditImgGet

或者直接运行任务

npm run redditImgGet

否则,我看不到srcReddit文件在哪里记录任何内容。