1.0.18 • Published 5 years ago

@artahian/node-app v1.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

node-app

A build tool that sets up Webpack, Babel, React and Express in your Node project so that you can start creating a full-stack JavaScript/React/Node/Express app without any setup

NPM Version

Install

npm install --save @artahian/node-app

Usage

After installing the package, run

node-app setup

node-app will automatically install the necessary build tools as dev dependencies in your project.

Add build, start and start:dev scripts to your package.json:

  "scripts": {
    "build": "node-app build",
    "start": "node-app start",
    "start:dev": "node-app start:dev",
    ...
  }

Structure your project in the following way:

  • src
    • client
      • index.html
      • index.js
    • server
      • app.js
  • public

    • ...some static assets that are publicly accessible, like images...

node-app exports a renderHome express handler that serves your index.html with the bundled index.js with all of its dependencies, which will usually contain your main React app.

In your src/server/app.js, import the express app from node-app and start the server. For example:

import express from 'express'; // Note that you don't have to install 'express' yourself, it comes with this package

import { app, renderHome } from '@artahian/node-app';

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.get('/', renderHome);

const port = process.env.PORT || 3000;

app.listen(port, () => {
  console.log(`Application started on port ${port}`);
});

Start your application by running:

npm start:dev

For production, use:

npm run build
npm start

node-app will generate a dist directory with the bundled versions.

License

MIT

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago