express-react-server
v0.1.2
Published
Utility module to build a server with react and express.
Downloads
3
Readme
express-react-server
Use react as a template for express Support dynamic React !!
Installation
npm install --save express-react-server
Basic templating usage
Used for rendering static html
Structure:
My directory
|- server.js
`- views
`- index.jsx
server.js
:
// Require path
const path = require('path')
// Init Express
const express = require('express')
const app = express()
// Require express react server
const reactServer = require('express-react-server')
// Define engine
app.engine('jsx', reactServer.createEngine())
// Define views
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'jsx')
// Basic route
app.get('/', function (req, res) {
res.render('index', {title: 'Express-React-Server', name: 'John Doe'})
})
// Listening on port
var port = 8000
app.listen(port, function () {
console.log('Server running on port: ' + port)
})
views/index.jsx
:
import React from 'react'
export default class extends React.Component {
render () {
return (
<html>
<head>
<title>{this.props.title}</title>
<meta charSet='utf-8' />
</head>
<body>
<p>
Hello, {this.props.name}!
</p>
</body>
</html>
)
}
}
Advanced templating Usage
Used for rendering dynamic html
Check the in the test directory
Other stuff
Forked from express-react-views. Code style stabdard.
License
See the license file