Skip to content

Neutrino Start Server Middleware

@neutrinojs/start-server is Neutrino middleware for starting a Node.js server for a file upon completion of a build.

NPM version NPM downloads

Requirements

  • Node.js 10+
  • Yarn v1.2.1+, or npm v5.4+
  • Neutrino 9
  • webpack 4

Installation

@neutrinojs/start-server can be installed via the Yarn or npm clients.

Yarn

❯ yarn add --dev @neutrinojs/start-server

npm

❯ npm install --save-dev @neutrinojs/start-server

Usage

@neutrinojs/start-server can be consumed from the Neutrino API, middleware, or presets. Require this package and plug it into Neutrino:

const startServer = require('@neutrinojs/start-server');

// Use with default options, starting the server
// for the main entry point, defaults to neutrino.options.mains.index
neutrino.use(startServer());

// Usage with custom server file to start
neutrino.use(
  startServer({
    name: 'custom.js',
    // Override pluginId to add an additional start-server plugin instance
    pluginId: 'start-server',
  }),
);
// Using in .neutrinorc.js
const startServer = require('@neutrinojs/start-server');

// Use with default options, starting the server
// for the main entry point, defaults to neutrino.options.mains.index
module.exports = {
  use: [startServer()],
};

// Usage with custom server file to start
module.exports = {
  use: [
    startServer({
      name: 'custom.js',
      // Override pluginId to add an additional start-server plugin instance
      pluginId: 'start-server',
    }),
  ],
};

By default this middleware will start a server with the first main entry point configured in Neutrino, by default src/index. This middleware optionally accepts an object with a name property for a path to a module which to start the server.

Customization

@neutrinojs/start-server creates some conventions to make overriding the configuration easier once you are ready to make changes.

Plugins

The following is a list of plugins and their identifiers which can be overridden:

Name Description NODE_ENV
start-server Start a Node.js for the first configured main entry point or specified file. all

Debugging

You can start the Node.js server in inspect mode to debug the process by setting neutrino.options.debug to true.

Contributing

This middleware is part of the neutrino repository, a monorepo containing all resources for developing Neutrino and its core presets and middleware. Follow the contributing guide for details.