I am attempting to run a file in my node environment on my macbook. I keep getting the following terminal error messages:
/.../filename.js: line 2: syntax error near unexpected token `('
/.../filename.js: line 2: `const fs = require('../build/index.js');'
code:
#!/usr/bin/env node
const fs = require('../build/index.js');
The command I'm giving is:
node index.js
(I know the file names are the same but its calling a different file.)
I can't seem to figure out why it is finding the extra `.
I have tried:
- Rewriting the code multiple times.
- I started a new file from scratch with the same name (filename.js).
- Running the code through jslint
- https://www.digitalocean.com/community/questions/syntax-error-near-unexpected-token-in-node-js-for-http
- I followed the exact formatting from this article: https://adrianmejia.com/blog/2016/08/12/getting-started-with-node-js-modules-require-exports-imports-npm-and-beyond/
- Using double quotes instead of single quotes
Little more background, this is a project I've picked up and this is my first time trying to run it.
EDIT: Code for index.js
'use strict';
var _child_process = require('child_process');
var _logger = require('./logger');
var _logger2 = _interopRequireDefault(_logger);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var l = new _logger2.default();
l.log('Starting backup');
var wd = __dirname.split('/');
var basePath = wd.slice(0, wd.length - 1).join('/');
var execPath = basePath + '/path/filename.js';
var stdout = (0, _child_process.execSync)('. ' + execPath + ' -a ' + basePath + '/something.json -b ' + basePath + '/backups');
l.log(stdout);