I'm trying to follow these instructions, and after I do the command prompt steps, it tells me to import and create an instance of the SparkPost class:
const SparkPost = require(‘sparkpost’)
const client = new SparkPost('YOUR API KEY')
But I have no idea where they want me to do that. Certainly not command prompt. There are dozens of files in the module they had me make, so I'm lost. Please help.
I've also looked here, but that left me just as confused. It's like they think I should already know.
UPDATE: I saved this code as index.js. here's a screenshot of my file structure
/*this is my code from the sparkpost tutorial*/
const SparkPost = require(‘sparkpost’);
const client = new SparkPost('XXX-my-api-XXX');
/*this is my code from the node.js tutorial mentioned in the comments*/
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
and here's what it looks like when I try to launch:
C:\Users\jacob\sparkpost-test>node index.js
C:\Users\jacob\sparkpost-test\index.js:1
(function (exports, require, module, __filename, __dirname) { const SparkPost = require(‘sparkpost’);
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3