简体   繁体   English

为什么我的Javascript文件不运行?

[英]Why doesn't my Javascript file run?

  "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"
  },

This is currently my package.json . 当前是我的package.json I am trying to call the script which obtains an image from reddit . 我正在尝试调用从reddit获取图像的脚本。 The inside of srcReddit.js is shown below: 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");

For this, I am using the wrapper snoowrap for the reddit API . 为此,我使用reddit API的包装器snoowrap Now when I do a npm start , I for some reason get this below: 现在,当我执行npm start ,出于某种原因,请在下面获取此信息:

在此处输入图片说明

No idea why the console.log messages do not appear. 不知道为什么console.log消息不出现。 Does anyone know why? 有人知道为什么吗?

npm start runs the start task and it does not refer to the redditImgGet task at any time, it seems. npm start运行start任务,它似乎在任何时候都没有引用redditImgGet任务。

I assume you should change your start task to 我认为您应该将start任务更改为

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

Or just run the task directly 或者直接运行任务

npm run redditImgGet

Otherwise, I don't see where you could expect the srcReddit file to log anything. 否则,我看不到期望srcReddit文件记录任何内容的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM