TypeError: Missing parameter name at 14

  javascript, koa, mongodb, mongoose, node.js

I am building a simple server on Javascript using node.js platform. I have 2 files which are called server.js and db.js. I found a weird error while testing server.js. Below you’ll find the 3 files in question. Any and all answers are greatly appreciated!

Error on node

C:UsersCharu NasaFinsectradebackendnode_modulespath-to-regexpdistindex.js:48
                throw new TypeError("Missing parameter name at " + i);
                ^

TypeError: Missing parameter name at 14
    at lexer (C:UsersCharu NasaFinsectradebackendnode_modulespath-to-regexpdistindex.js:48:23)
    at parse (C:UsersCharu NasaFinsectradebackendnode_modulespath-to-regexpdistindex.js:98:18)
    at stringToRegexp (C:UsersCharu NasaFinsectradebackendnode_modulespath-to-regexpdistindex.js:331:27)
    at pathToRegexp (C:UsersCharu NasaFinsectradebackendnode_modulespath-to-regexpdistindex.js:405:12)
    at new Layer (C:UsersCharu [email protected]:43:17)
    at Router.register (C:UsersCharu [email protected]:570:17)
    at Router.<computed> [as get] (C:UsersCharu NasaFinsectradebackendnod[email protected]:200:12)
    at Object.<anonymous> (C:UsersCharu NasaFinsectradebackendserver.js:11:8)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Code file:

Server.js

const Koa = require('koa');

const Router = require('@koa/router');

const cors = require('@koa/cors');

const ethers = require('ethers');

const Paymentframework = require('../build/contracts/Paymentframework.json');

const {Payment} = require('./db.js');

const app = new Koa();

const router = new Router();

router.get('/api/getpayID/: AssetID', async (ctx) => {
    ctx.body = 'goldasset'; 
});

app
 .use(cors())
 .use(router.routes())
 .use(router.allowedMethods());

 app.listen (4000, () =>{
    console.log('Server running on port 4000');
 }); 

db.js

const mongoose = require ('mongoose');

mongoose.connect(
'your connection string', 
'mongodb+srv://abcd:<abcd1234>@finsectrade.di8n0.mongodb.net/<finsectrade >?retryWrites=true&w=majority',
{useNewUrlParser: true, useUnifiedTopology: true}
);

const paymentSchema = new mongoose.Schema({
    id: String,
    AssetID: String,
paid: Boolean}
);

const Payment = mongoose.model('Payment', paymentSchema);

 module.exports = {
    Payment
 };
 

Source: Ask Javascript Questions

LEAVE A COMMENT