Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@moped/start-server
Advanced tools
Readme
This module provides an easy way to run a webpack bundle in node.js with hot reloading. It is part of the moped suite of utilities for creating composable configs for building node.js and react apps.
This module uses a custom hot reloader to do hot-reloading of individual modules if you use module.accept
, and fall back to restarting the entire server if there are syntax errors or runtime errors or a module was not handled by module.accept
.
yarn add --dev @moped/start-server
There are two ways to use start-server. One for HTTP servers, which renders errror pages when in the error states, and queues incoming requests during the build process. The other for any kind of node.js app.
N.B. This plugin includes the
webpack.HotModuleReplacementPlugin
plugin, so if you have that plugin already in your config, you must remove it.
const StartServerPlugin = require('@moped/start-server');
module.exports = {
entry: __dirname + '/src/index.js',
output: {
path: __dirname + '/build',
filename: 'server.js',
},
plugins: [
new StartServerPlugin({env: {PORT: 3000}}),
]
};
This file just handles hot reloading and actually listening on a port. This lets webpack replace individual modules for most reloads, rather than rebooting the entire node process.
if (process.env.NODE_ENV === 'production') {
require('./server').listen(process.env.PORT);
} else {
const setServer = require('@moped/start-server/dev-server');
setServer(require('./server'));
module.hot.accept('./server', () => {
setServer(require('./server'));
});
}
This is your actual server. Can be an express server, or anything that exports a function that takes req
and res
as the two arguents.
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World');
});
module.exports = app;
This setup automatically shuts down the node process for any compiler errors or uncaught runtime errors, restarting it on the first successful build. It will do hot module replacement wherever possible, and fall back to restarting the entire node process if hot module replacement fails.
const StartServerPlugin = require('@moped/start-server');
module.exports = {
entry: [
// this additional entry restarts the node process for updates
StartServerPlugin.hotEntry,
__dirname + '/src/index.js'
],
output: {
path: __dirname + '/build',
filename: 'server.js',
},
plugins: [
new StartServerPlugin(/* {...options} */),
]
};
MIT
FAQs
This module provides an easy way to run a webpack bundle in node.js with hot reloading. It is part of the moped suite of utilities for creating composable configs for building node.js and react apps.
The npm package @moped/start-server receives a total of 58 weekly downloads. As such, @moped/start-server popularity was classified as not popular.
We found that @moped/start-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.