New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-while

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-while

A CLI command to start up a node server, execute another CLI command (while node server is still running) and then exit the node server.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

A CLI command to start up a node server, execute another CLI command (while node server is still running) and then exit the node server.

NPM Version Linux CI Build Windows CI Build Known Vulnerabilities

Why on earth would you want that?

I created node-while for my specific use case - I wanted to start up my node server, run my integration tests and then stop the server (all via a single CLI command). This seemed like a reasonable way to do it + I thought it might be useful for someone else.

Install

npm install node-while

Usage

To be used with node-while, your node server needs to do 2 things;

  • export the express app instance as default
  • emit the event 'ready' when the server has finished init (e.g. connected to DB) and is ready to recieve requests

e.g.

//For ES6
import express from 'express';
const app = express();

const server = app.listen('8080', function () {
  //2. emit a 'ready' event when server is ready for interaction
  server.emit('ready');
});

//1. export the app instance as default
export default server;
//or for vanilla ES5
var express = require('express');
var app = express();

var server = app.listen('8080', function () {
  //2. emit a 'ready' event when server is ready for interaction
  server.emit('ready');
});

//1. export the app instance as default
exports.default = server;

You can use node-while like so

npx node-while -server ./src/myServer.js -run "echo squanch"

(concrete example) In my particular case I use node-while to run my cypress integration tests

npx node-while -s ./dist/server/index.js -run "npx cypress run"

See node-while -h for addition params

Help, my server code uses babel/typscript

node-while doesnt currently have hooks for transpilers etc. Current recommendation is to transpile code e.g. with babel CLI (as your probably doing for production anyway) and then execute that with node-while.

Keywords

node

FAQs

Package last updated on 14 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts