Saturday 27 May 2017

npm module for clarifai not found when I start the node server

module.js:341
    throw err;
    ^

Error: Cannot find module 'clarifai'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/shiva/seefood-backend/app.js:4:16)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)

I get the above message in terminal when I do node app.js. I have installed Clarifai npm package as mentioned on https://developer.clarifai.com/quick-start/ with npm install clarifai but it still gives me this error. Do I need to install the package globally? Also this is my app.js :

var express = require('express')
var app = express();
var bodyParser = require('body-parser')
var Clarifai = require('clarifai')
var secrets = require('./secrets')
var keys = secrets.clarifaiConfig()

app.use(bodyParser.json());

var ClarifaiInstance = new Clarifai.App(
  keys.access_key,
  keys.secret_key
)

var store

var foodModel = 'bd367be194cf45149e75f01d59f77ba7'
var fnol = function getPredictionAsJSON(imageURL) {
  ClarifaiInstance.models.predict(foodModel, imageURL).then(
    function(response) {
      store = response.outputs[0].data
      console.log(store + ' from inside the fn');
    },
    function(err) {
      console.error(err);
    }
  );
  return store
}

app.listen(8000, function () {
  console.log('Recognize app listening on port 8000!')

  app.post('/classify', function(req, res) {
    var clarifaiData
    var imageURL = req.body.imageURL
      clarifaiData = fnol(imageURL)
      // console.log('cldata : '+ clarifaiData)
      var responseObject = {imageURL: imageURL, data: clarifaiData }
      // console.log('rObj : '+responseObject)
      res.send((responseObject));
  });

  app.get('/classify', function(req, res) {
    res.json((store));
  });
})



via ShivaV

No comments:

Post a Comment