Home > Web Front-end > JS Tutorial > Testing Express.js using node-plug

Testing Express.js using node-plug

Patricia Arquette
Release: 2025-01-04 01:44:43
Original
143 people have browsed it

The first step is installation of node-plug and express.js

npm install node-plug
Copy after login
npm install express
Copy after login

Create a test file for example 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!'

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

// 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}`)
})

Copy after login

After that, create a file, for example main.js or 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!',
  },
])*/
Copy after login

Output:

Melakukan pengujian Express.js menggunakan node-plug

Melakukan pengujian Express.js menggunakan node-plug

JSON output:

Melakukan pengujian Express.js menggunakan node-plug

Melakukan pengujian Express.js menggunakan node-plug

The above is the detailed content of Testing Express.js using node-plug. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template