Message Mixer Step 6

Hello All,

I am on step 6 of message mixer and I get the following error on bash when i type ‘node message-mixer.js caesar 4’:

ReferenceError: caesarCipher is not defined
    at Object.<anonymous> (/home/ccuser/workspace/modules-message-mixer/encryptors.js:3:31)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/ccuser/workspace/modules-message-mixer/message-mixer.js:3:21)
    at Module._compile (module.js:571:32)

Here is my encryptors.js:

// Declare and export the functions here.

module.exports.cC= caesarCipher;
module.exports.sC = symbolCipher;
module.exports.rC = reverseCipher;

// Encryption Functions
/////////////////////////////////////////////

const caesarCipher = (str, amount = 0) => {
  if (amount < 0) {
    return caesarCipher(str, amount + 26);
  }
  let output = '';
  for (let i = 0; i < str.length; i++) {
    let char = str[i];
    if (char.match(/[a-z]/i)) {
      let code = str.charCodeAt(i);
      if (code >= 65 && code <= 90) {
        char = String.fromCharCode(((code - 65 + amount) % 26) + 65);
      } else if (code >= 97 && code <= 122) {
        char = String.fromCharCode(((code - 97 + amount) % 26) + 97);
      }
    }
    output += char;
  }
  return output;
};

const symbolCipher = (str) => {
  const symbols = {
    'i': '!',
    '!': 'i',
    'l': '1',
    '1': 'l',
    's': '$',
    '$': 's',
    'o': '0',
    '0': 'o',
    'a': '@',
    '@': 'a',
    'e': '3',
    '3': 'e',
    'b': '6',
    '6': 'b'
  }

  let output = '';
  for (let i = 0; i < str.length; i++) {
    let char = str.toLowerCase()[i];

    if (symbols[char]) {
      output += symbols[char]
    } else {
      output += char;
    }
  }
  return output;
}

const reverseCipher = (sentence) => {
  let words = sentence.split(' ');
  for (let i = 0; i < words.length; i++) {
    words[i] = words[i].split('').reverse().join('');
  }
   return words.join(' ');
};
////////////////////////////////////////////////////////////////////////////////

Here is my message-mixer.js:

// Import the functions from encryptors.js here.h
 
 const encryptors = require('./encryptors.js');


const caesarCipher = encryptors.cC;
const symbolCipher = encryptors.sC;
const reverseCipher = encryptors.rC;


// User Input / Output Logic
/////////////////////////////////////////////

const encryptionMethod = getEncryptionMethod();
process.stdin.on('data', (userInput) => {
  displayEncryptedMessage(encryptionMethod, userInput);
});

/* Helper function for determining which cipher method
the user chose when they ran the program. */
function getEncryptionMethod() {
  let encryptionMethod;
  
  const encryptionType = process.argv[2];  
  if (encryptionType === 'symbol') {
    encryptionMethod = symbolCipher;
  } else if (encryptionType === 'reverse') {
    encryptionMethod = reverseCipher;
  } else if (encryptionType === 'caesar') {
    let amount = Number(process.argv[3]);
    if (Number.isNaN(amount)) {
      process.stdout.write(`Try again with a valid amount argument. \n`)
      process.exit();  
    }
    encryptionMethod = (str) => caesarCipher(str, amount);
  } 
  else {
    process.stdout.write(`Try again with a valid encryption type. \n`)
    process.exit();
  }

  process.stdout.write('Enter the message you would like to encrypt...\n> ');
  return encryptionMethod;
}

/* Helper function for displaying the encrypted message to the user. */
function displayEncryptedMessage(encryptionMethod, userInput) {
  let str = userInput.toString().trim();    
  let output = encryptionMethod(str);
  process.stdout.write(`\nHere is your encrypted message:\n> ${output}\n`)
  process.exit();
}

I am not sure how to fix this error. Any hints and suggestions would be much appreciated.
Thank You

here is the link to the exercise: https://www.codecademy.com/courses/introduction-to-javascript/projects/message-mixer-node

This is how I get mine to work:

// Import the functions from encryptors.js here.

const encryptors = require(’./encryptors.js’);

// Encryption Functions

/////////////////////////////////////////////

const caesarCipher = encryptors.caesarCipher(’’);

const symbolCipher = encryptors.symbolCipher;

const reverseCipher = encryptors.reverseCipher;

@saiswr You may have solved it with the post from christ_maximus but wanted to give more specifics to what you have wrong.
Your 3 module.exports calls must be at the end of the encryptors.js file and not at the top. The functions need to be defined first, then exported.
The CC comment at the top of the file:
// Declare and export the functions here.
is confusing and it refers to the whole document not that location at the top of the file. You declare first, then export.

This is very helpful thank you. The part about first declaring and then exporting is very important and surely very basic and but is not explained in the lesson. There was a whole lesson about hoisting but here not a line. Also all the node stuff is just thrown at you. Not a good exercise IMHO.