DEV Community

Salman
Salman

Posted on

Melakukan pengujian Express.js menggunakan node-plug

Langkah pertama instalasi node-plug dan express.js

npm install node-plug
Enter fullscreen mode Exit fullscreen mode
npm install express
Enter fullscreen mode Exit fullscreen mode

Buat file pengujian misalnya test.js

import express from 'express'

const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send(message)
})

const message = 'Halo dari Express dalam sebuah plugin!'

// atau kirim sebagai JSON
// const message = { message: 'Halo dari Express dalam sebuah plugin!' }

export const t = {
  async run() {
    await console.log(message)
  },
}

app.listen(port, () => {
  console.log(`Server berjalan di http://localhost:${port}`)
})

Enter fullscreen mode Exit fullscreen mode

Setelah itu buat file, misalnya main.js atau index.js

import { addPlugin, runPlugin, test } from 'node-plug'
import { t } from './test.js'

// Menambahkan plugin
addPlugin(t)

// Menjalankan plugin
runPlugin()

// Melakukan pengujian
test(['Halo dari Express dalam sebuah plugin!'])

// Melakukan pengujian sebagai JSON
/*test([
  {
    message: 'Halo dari Express dalam sebuah plugin!',
  },
])*/
Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Image description

Output JSON:

Image description

Image description

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay