Can not find module

-2

I'm following this tutorial to create a chatbot of the link below, and you're giving this error, someone Can you help me with the error? the error and in the file server.js or in dialogflow.js?

dialogflow.js

const axios = require('axios')
const accessToken = process.env.DIALOGFLOW_ACCESS_TOKEN
const baseURL = 'https://api.dialogflow.com/v1/query?v=20150910'

module.exports = {

send (message) {

    const data = {
      query: message,
      lang: 'pt-BR',
      sessionId: '123456789!@#$%'
    }
    return axios.post(baseURL, data, {
      headers: { Authorization: 'Bearer ${accessToken}' }
    })
  }
}

server.js

const express = require('express')
const bodyParser = require('body-parser')
const Pusher = require('pusher')
const cors = require('cors')
require('dotenv').config()
const shortId = require('shortid')
const dialogFlow = require('./dialogFlow')
const app = express()

app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

const pusher = new Pusher({
  appId: process.env.PUSHER_APP_ID,
  key: process.env.PUSHER_APP_KEY,
  secret: process.env.PUSHER_APP_SECRET,
  cluster: 'eu',
  encrypted: true
})

app.post('/message', async (req, res) => {
  // simulate actual db save with id and createdAt added
  console.log(req.body);

  const chat = {
    ...req.body,
    id: shortId.generate(),
    createdAt: new Date().toISOString()
  }

  //update pusher listeners

  pusher.trigger('chat-bot', 'chat', chat)

  const message = chat.message;
  const response = await dialogFlow.send(message);

  // trigger this update to our pushers listeners

  pusher.trigger('chat-bot', 'chat', {
    message: '${response.data.result.fulfillment.speech}',
    type : 'bot',
    createdAt : new Date().toISOString(),
    id: shortId.generate()
  })

  res.send(chat)
})

app.listen(process.env.PORT || 5000, () => console.log('Listening at 5000'))

error

module.js:549
     throw err;
     ^

Error: Cannot find module './dialogFlow'
     at Function.Module._resolveFilename (module.js:547:15)
     at Function.Module._load (module.js:474:25)
     at Module.require (module.js:596:17)
     at require (internal/module.js:11:18)
     at Object.<anonymous> (/home/marco/Documentos/trabalho/chatbot/chatbotapp/server.js:7:20)
     at Module._compile (module.js:652:30)
     at Object.Module._extensions..js (module.js:663:10)
     at Module.load (module.js:565:32)
     at tryModuleLoad (module.js:505:12)
     at Function.Module._load (module.js:497:3)
    
asked by anonymous 30.10.2018 / 22:57

1 answer

1

The file name is reported as dialogflow.js and you are importing dialogFlow . Use require as follows if the files are in the same folder:

const dialogFlow = require('./dialogflow');
    
31.10.2018 / 13:19