2
votes

I'm trying to start react-js app with node server. Structure of directory: MyTodo

---bin/

------css/

------fonts/

------js/

------index.html

---sources/

------App.jsx

------TodoGroup/

file server.js:

 var express=require('express');
var app=express();

app.set('port',(process.env.PORT||3000));

app.use('/',express.static(__dirname));

app.listen(app.get('port'), function() {
	console.log('Server started: http://localhost:'+app.get('port')+'/');
});

webpack.config:

var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

var config = module.exports = {
    context: __dirname,
    entry: {
        'App': './sources/App.jsx',
    },

    output: {
        path: './bin/js',
        filename: '[name].js'
    },

    plugins: [
        new ExtractTextPlugin('../css/[name].css')
    ],

	devServer: {
        contentBase: ".",
        host: "localhost",
        port: 3000
    },
	
   module:{
        loaders:[   //загрузчики
            {
                test: /\.jsx?$/, // определяем тип файлов
                exclude: /(node_modules)/,
                loader: "babel-loader",
                query:{
                    presets:["es2015", "react"]
                }
            }
        ]
    }

    resolve: {
        extensions: ['', '.js', '.jsx']
    }
}

In browser http://localhost:3000/ shows an error: GET http://localhost:3000/ 404 (Not Found)

1
where is your server.js? Assuming it is in parent of bin/, then update the app.use('/',express.static(path.join(__dirname, "bin/"))); Import path too.Mukesh Sharma
thank you, Molda's answer worksOlga

1 Answers

1
votes

You don't have any route for handling http://localhost:3000/

You have only static file handler which means this url would probably work http://localhost:3000/index.html

If you want to access your web at http://localhost:3000/ then add this

app.get('/', function(req, res){
    res.sendFile(__dirname+'/bin/index.html'); // change the path to your index.html
});