npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

create-react-ssr-layout

v1.3.7

Published

A useful tool to quickly build a starting express server that uses custom SSR with a custom jsx render engine

Downloads

14

Readme

create-react-ssr-layout

A useful npx tool to quickly build a basic express server that uses a custom-built SSR engine.

Check out this package on npm

And on GitHub

Usage

Simply run this command in your terminal

npx create-react-ssr-layout@latest

to setup a project in the current directory or

npx create-react-ssr-layout@latest <projectname>

Answer questions via cli and pick a server build. You may use a predefined one or customize the build on your own. All required dependencies will be installed automatically.

Quick start

Execute this package

npx create-react-ssr-layout@latest .

Answer some questions and wait until all files are created and all dependencies are installed. To launch the server use

npm start

The server starts on port 3000 by default. Go to http://localhost:3000/ to open the page.

Scripts

npm start

Executes webpack to create bundles and then launches the server on a specified port via babel-node.

npm run deps

Installs all chosen dependencies at once. Picking "Maximum server" option will install the following

  • dependencies: express, react, react-dom, react-router-dom, sequelize, pg, pg-hstore, dotenv, express-session, session-file-store, bcrypt, axios
  • devDependencies: @babel/node, @babel/plugin-proposal-class-properties, @babel/preset-react, @babel/preset-env, babel-loader, morgan, webpack, webpack-cli, sequelize-cli

The option "Minimum server" will install the following

  • dependencies: express, react, react-dom
  • devDependencies: @babel/node, @babel/preset-react, @babel/preset-env

Each custom option picked adds required dependencies and/or devDependencies.

npm run launch

Performs migrations and seeds a database. Then executes webpack and launches the server. Before executing this script run npx sequelize-cli --init, prepare and configure a database, make required changes to .env file.

npm run dev

Only starts the server.

npm run webpack

Starts webpack in watch mode.

Project tree

.
├── package.json
├── .babelrc
├── .env
├── .eslintrc.js
├── .gitignore
├── .prettierrc
├── .sequelizerc
├── src
│   ├── components
│   │   ├── App.jsx
│   │   ├── index.jsx
│   │   └── Layout.jsx
│   ├── middlewares
│   │   └── resLocals.js
│   ├── routes
│   │   ├── apiRouter.js
│   │   └── indexRouter.js
│   ├── server.js
│   └── utils
│       └── jsxRender.js
└── webpack.config.js

Used packages

  • React-based
    • react
    • react-dom
    • react-router-dom
  • Server-based
    • express
    • express-session
    • session-file-store
    • dotenv
    • morgan
    • bcrypt
    • axios
  • Sequelize
    • sequelize
    • sequelize-cli
    • pg
    • pg-hstore
  • Babel
    • @babel/node
    • @babel/plugin-proposal-class-properties
    • @babel/preset-react
    • @babel/preset-env
  • Webpack
    • webpack
    • webpack-cli
    • babel-loader

SSR

The server uses custom jsx render engine that constructs a markup on the server side via renderToString() method from react-dom/server. The object initState is used to deliver data from server through props directly to the App.jsx component. For routing purposes req.originalUrl is included into res.locals.

Two routers are added for convenience. indexRouter uses res.render method for rendering markups. res.render requires a string Layout to be passed as its first argument. The second argument may be ommited. Use it to pass props to App.jsx.

Layout.jsx has basic HTML markdown. It uploads webpack scripts app.js and vendor.js and uses dangerouslySetInnerHTML to pass initState to client side for the hydration process (if an option webpack with hydration was picked).

Issues

Use GitHub issues to report about any problems or bugs