10 examples of 'npm serve' in JavaScript

Every line of 'npm serve' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
149function serve(args) {
150
151 var server = './scripts/';
152
153 var options = {
154 script: server + 'app.js',
155 delayTime: 1,
156 env: {
157 'NODE_ENV': args.mode,
158 'PORT': server_port
159 },
160 watch: [server]
161 };
162
163 return plug.nodemon(options)
164 .on('start', function() {
165 startBrowserSync();
166 gulp.watch('./src/**/*.scss', ['build']);
167 gulp.watch('./src/**/*.{html,js}', ['build']);
168 })
169 //.on('change', tasks)
170 .on('restart', function() {
171 log('restarted!');
172 setTimeout(function() {
173 browserSync.reload({
174 stream: false
175 });
176 }, 1000);
177 });
178}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

339function serve(args) {
340 var options = {
341 script: pkg.paths.server + 'app.js',
342 delayTime: 1,
343 ext: 'html js',
344 env: {'NODE_ENV': args.env},
345 watch: [
346 'gulpfile.js',
347 'package.json',
348 pkg.paths.server,
349 pkg.paths.client
350 ]
351 };
352
353 if (args.debug) {
354 gulp.src('', {read: false})
355 .pipe(plug.shell(['node-inspector']));
356 options.nodeArgs = [args.debug + '=5858'];
357 }
358
359 return plug.nodemon(options)
360 //.on('change', tasks)
361 .on('restart', function() {
362 log('restarted!');
363 });
364}
622function commandServe(): void {
623 const hasMarked = sysFs.existsSync(sysPath.posix.join(__dirname,
624 '../node_modules/marked/bin/marked'));
625 const hasHighlightJs = sysFs.existsSync(sysPath.posix.join(__dirname,
626 '../node_modules/highlight.js/lib/index.js'));
627
628 const port = argOpts['port'].value as int || DEFAULT_PORT;
629 const allowDirListing = argOpts['listDir'].hasOption;
630
631 new HttpServerEx.ServerEx(port, isVerbose, 'EXIT_SERVER',
632 allowDirListing, hasMarked, hasHighlightJs).start();
633
634 if (logLevel >= Consts.LL_SILENT) {
635 if (hasMarked) {
636 console.log(`Using markdown compiler`);
637 }
638 console.log(`Serving on http://localhost:${port}/`);
639 if (allowDirListing) {
640 console.log(`Directory listing on http://localhost:${port}/?dir`);
641 }
642 }
643}
15async function startServer() {
16 process.stdout.write(chalk.green('\nStarting local server hosting production build...'));
17 const server = new StaticServer({
18 rootPath: './docs',
19 port: APP_PORT
20 });
21
22 await new Promise(resolve => {
23 server.start(() => resolve());
24 });
25
26 global.__SERVER__ = server;
27 process.stdout.write(chalk.green('done ✓'));
28}
43function serve(req, res, baseDir) {
44 console.log('serve');
45 var dataStr = '';
46 req.on('data', function(chunk) {
47 dataStr += chunk;
48 });
49 req.on('end', function() {
50 serveGet(req, res, dataStr);
51 });
52}
8module.exports = function serve(port, host) {
9 const targetHost = host || 'localhost';
10 const targetPort = port || 8080;
11
12 process.env.NODE_ENV = 'development';
13 process.env.HOST = targetHost;
14 process.env.PORT = targetPort;
15
16 const webpackConfig = require('../config/webpack.config');
17 const compiler = webpack(webpackConfig);
18 const server = new WebpackDevServer(compiler, {
19 hot: true,
20 stats: {
21 colors: true,
22 },
23 });
24
25 server.listen(targetPort, targetHost, () => {
26 console.log();
27 console.log(chalk.gray(`Starting server at ${chalk.green(`http://${targetHost}:${targetPort}`)}`));
28 console.log();
29 });
30};
19function serve (done) {
20 browsersync.init({
21 open: false,
22 server: {
23 baseDir: path.join(__dirname, 'redaxo.docset/Contents/Resources'),
24 directory: true
25 }
26 })
27 done()
28}
42function serve(isDev, specRunner) {
43 var debug = options.debug;
44 var debugMode = options.debugBrk ? '--debug-brk' : options.debug ? '--debug' : '';
45 var nodeOptions = getNodeOptions(isDev);
46
47 if (debug) {
48 runNodeInspector();
49 nodeOptions.nodeArgs = [debugMode + '=5858'];
50 }
51
52 if (options.verbose) {
53 console.log(nodeOptions);
54 }
55
56 return nodemon(nodeOptions)
57 .on('restart', ['vet'], function(ev) {
58 log('*** nodemon restarted');
59 log('files changed:\n' + ev);
60 setTimeout(function() {
61 browserSync.notify('reloading now ...');
62 browserSync.reload({stream: false});
63 }, config.browserReloadDelay);
64 })
65 .on('start', function() {
66 log('*** nodemon started');
67 startBrowserSync(isDev, specRunner);
68 })
69 .on('crash', function() {
70 log('*** nodemon crashed: script crashed for some reason');
71 })
72 .on('exit', function() {
73 log('*** nodemon exited cleanly');
74 });
75}
124function serve(done) {
125 server.init({
126 proxy: `http://${config.get("server-host")}:${config.get("server-port")}`,
127 files: [paths.styles.dest],
128 browser: "google chrome",
129 port: config.get("browsersync-port")
130 });
131
132 done();
133}
5module.exports = function serve(program) {
6 const webpackConf = conf(program);
7 const compiler = webpack(webpackConf);
8 compiler.run((err, stats) => {
9 // 官方输出参数
10 // https://webpack.js.org/configuration/stats/
11 // https://github.com/webpack/webpack/issues/538#issuecomment-59586196
12 /* eslint-disable */
13 console.log(stats.toString({
14 colors: true,
15 children: false,
16 chunks: false,
17 modules: false,
18 moduleTrace: false,
19 warningsFilter: (warning) => {
20 return true
21 }
22 }));
23 /* eslint-enable */
24 });
25};

Related snippets