项目作者: kriasoft

项目描述 :
Restart Node.js app in development mode
高级语言: JavaScript
项目地址: git://github.com/kriasoft/restart.git
创建时间: 2018-04-16T11:23:19Z
项目社区:https://github.com/kriasoft/restart

开源协议:MIT License

下载


Node.js Restart

NPM version
NPM downloads
Build Status

This module is designed to restart Node.js app in development mode, e.g. after compilation with
Babel/TypeScript is complete.

How to Install

  1. $ npm install restart --save-dev

How to Use

build/app.js

  1. const express = require('express');
  2. const app = express();
  3. let count = 0;
  4. app.get('/', (req, res) => {
  5. res.send(`count: ${++count}`);
  6. });
  7. module.exports = app.listen(8080);

server.js

  1. if (process.env.NODE_ENV === 'production') {
  2. // In a production environment launch the Node.js app directly.
  3. require('./build/app');
  4. } else {
  5. // Otherwise, start building the app from source and
  6. // restart it upon new changes in the /build folder.
  7. const restart = require('restart');
  8. const build = require('./scripts/build');
  9. build({
  10. watch: true,
  11. onComplete: () => {
  12. restart({ entry: './build/app' });
  13. },
  14. });
  15. }
  1. $ node ./server

License

Copyright (c) 2018-present Kriasoft | MIT License