Skip to content

Test application with react, node.js and express in a isomorphic proyect

License

Notifications You must be signed in to change notification settings

patapron/react-node.js-express-isomorphic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-node.js-express-isomorphic

Test application with react, node.js and express in a isomorphic proyect

How to start

Pre-requisites

  1. Install Node & Npm

  2. Create new proyect folder and an empty file named server.js

  3. Open new console and go to proyect folder

  4. Start node proyect:

npm int
  1. Fill proyect info

  2. Install dependecies:

npm install react express --save
  1. Edit server.js:
//helps js files reads
require('node-jsx').install({harmony:true});
var express = require('express');
var reactEngine = require('react-engine');

//create express instance
var app = express();

//locate files setup

//views
app.set('views',__dirname + '/src/views');

//statics files
app.use(express.static(__dirname + '/public'));

//helps js files render
var engine = reactEngine.server.create();

//setup what is the engine (jsx)
app.engine('.jsx', engine);

//setup to view use jsx
app.set('view engine', 'jsx');

//to read and access to thew views
app.set('view', reactEngine.expressView);

//server route access
app.get('/', function(req, res){
	res.render('home', {
		title: 'First Isomorphic App'
	});
});

//server start port
app.listen(3000, function(){
	console.log('server run in port 3000');
});
  1. Create src/views/home.jsx view and add:
var React = require('react');

var Home = React.createClass({
	render: function(){
		return (
			<h1>{this.props.title}</h1>
			)
	}
});

module.exports = Home;
  1. Try to run node server like (may be require admin permissions):
node server

or

node server.js
  1. Open sever in the browser at localhost:3000

About

Test application with react, node.js and express in a isomorphic proyect

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published