我有文件,我认为应该将其作为模块导入,但是当我尝试导入主文件(请参阅 main.js)时,出现以下错误:
Error: Cannot find module 'sessionStore.js'
我确保文件在正确的位置。任何想法还有什么可能导致这种情况?
main.js
var express = require('express');
var bodyParser = require('body-parser');
var util = require('util');
var toMarkdown = require('to-markdown');
var jsdiff = require('diff');
var marked = require('marked');
var pg = require('pg');
//need to get sessions to work and use server credentials instead of password
var sessionStore = require('sessionStore.js');
var PodioJS = require('podio-js').api;
var podio = new PodioJS({authType: 'password', clientId: "xxx", clientSecret: "xxx" },{sessionStore:sessionStore});
sessionStore.js
var fs = require('fs');
var path = require('path');
function get(authType, callback) {
var fileName = path.join(__dirname, 'tmp/' + authType + '.json');
var podioOAuth = fs.readFile(fileName, 'utf8', function(err, data) {
// Throw error, unless it's file-not-found
if (err && err.errno !== 2) {
throw new Error('Reading from the sessionStore failed');
} else if (data.length > 0) {
callback(JSON.parse(data));
} else {
callback();
}
});
}
function set(podioOAuth, authType, callback) {
var fileName = path.join(__dirname, 'tmp/' + authType + '.json');
if (/server|client|password/.test(authType) === false) {
throw new Error('Invalid authType');
}
fs.writeFile(fileName, JSON.stringify(podioOAuth), 'utf8', function(err) {
if (err) {
throw new Error('Writing in the sessionStore failed');
}
if (typeof callback === 'function') {
callback();
}
});
}
module.exports = {
get: get,
set: set
};