Welcome to the Linux Foundation Forum!

Mocking GET Routes (7): SyntaxError: Unexpected identifier

kestutis
kestutis Posts: 1
edited April 28 in LFW111 Class Forum

mock-srv$ npm run dev

mock-srv@1.0.0 dev
fastify start -w -l info -P app.js

SyntaxError: Unexpected identifier
at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:152:18)
at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:298:14)
at async link (node:internal/modules/esm/module_job:67:21)

mock-srv$ npx fastify start -w -l info -P app.js
SyntaxError: Unexpected identifier
at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:152:18)
at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:298:14)
at async link (node:internal/modules/esm/module_job:67:21)

$ node -v
v18.19.1

app.js:
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import AutoLoad from '@fastify/autoload'
import cors from '@fastify/cors'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

// Pass --options via CLI arguments in command to enable these options.
export const options = {}

export default async function (fastify, opts) {
// Place here your custom code!
fastify.register(cors)
// Do not touch the following lines

// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
options: Object.assign({}, opts)
})

// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes'),
options: Object.assign({}, opts)
})
}

Categories

Upcoming Training