我正在使用stormpath和node.js編寫一個API。 然而,當我試圖在節點上運行腳本create_user它給了我一個錯誤:「語法錯誤:!意外標記=」node.js SyntaxError:意外的令牌!=
這是我的tools.js文件:
var stormpath = require('stormpath')
var util = require ('util');
var appHref = 'https://api.stormpath.com/v1/applications/KzUPEioLybUfu2YwUjb8o';
var client;
var app;
// Find the user's home directory (works on both Windows and *nix):
var home = process.env[(process.platform === 'win32' ? 'USERPROFILE' : 'HOME')];
var apiKeyFilePath = home + '/.stormpath/apiKey.properties';
module.exports = {
createClient: function (apiKeyFilePath) {
this.createClient ={
if (apiKeyFilePath != 'undefined') {
stormpath.loadApiKey(apiKeyFilePath, function apiKeyFileLoaded(err, apiKey) {
client = new stormpath.Client({ apiKey: apiKey });
console.log('apiKey found... Client Created');
});
}
else {
var apiKey = new stormpath.ApiKey(
process.env['STORMPATH_CLIENT_APIKEY_ID'],
process.env['STORMPATH_CLIENT_APIKEY_SECRET']
);
var client = new stormpath.Client({ apiKey: apiKey });
console.log('apiKey created... Client Created');
}
}
},
createUser: function() {
this.createUser={
this.createClient;
client.getDirectory(usersHref, callback);
var account = {
username: 'example',
email: '[email protected]',
password: 'Changeme!'
};
RMFapp.createAccount(account, function(err, createdAccount) {
console.log(createdAccount);
});
}
}
};
這是我create_user.js文件:
var stormpath = require('stormpath')
var util = require ('util');
var tools = require('./tools');
var appHref = 'https://api.stormpath.com/v1/application/KzUPEioLybUfu2YwUjb8o';
var usersHref = 'https://api.stormpath.com/v1/directories/13tj6f50q7jJ7WvDu6SxHa';
var client;
var app;
console.log(tools.createUser);
當我運行節點create_user.js這是響應:
if (apiKeyFilePath != 'undefined') {
SyntaxError: Unexpected token !=
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/spiffysaxman/projects/RMFapp/RMF/www/assets/api/v1/create_user.js:3:13)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
請幫幫忙!
我有人建議我乾脆刪除this.createClient = {...)和this.createUser = {...),但是當我刪除那些我只是得到這個回報:「[Function]」
這是上面的一行:'this.createClient = {'我不認爲你在這裏意味着這條線(我認爲你的意思只是上面的createClient函數定義 – rgthree