Skip to content

node js es6 import #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xgqfrms-GitHub opened this issue May 12, 2017 · 6 comments
Open

node js es6 import #2

xgqfrms-GitHub opened this issue May 12, 2017 · 6 comments

Comments

@xgqfrms-GitHub
Copy link
Owner Author

@xgqfrms-GitHub
Copy link
Owner Author

@xgqfrms-GitHub
Copy link
Owner Author

{
    "name": "node-express4-restful-api",
    "version": "4.15.2",
    "description": "RESTful-API-Node-Express4, xgqfrms",
    "main": "index.js",
    "scripts": {
        "start": "node server.js",
        "run": "node server.js"
    },
    "repository": {
        "type": "git",
        "url": "git+https://github.com/xgqfrms/node-express4-restful-api.git"
    },
    "keywords": [
        "RESTful",
        "API",
        "Node",
        "Express4",
        "MongoDB",
        "Mongoose"
    ],
    "author": "xgqfrms, webgeeker",
    "license": "MIT",
    "bugs": {
        "url": "https://github.com/xgqfrms/node-express4-restful-api/issues"
    },
    "homepage": "https://github.com/xgqfrms/node-express4-restful-api#readme",
    "dependencies": {
        "body-parser": "^1.17.1",
        "express": "^4.15.2",
        "mongoose": "^4.9.8",
        "morgan": "^1.8.1"
    }
}

@xgqfrms-GitHub
Copy link
Owner Author

// configure our application and create routes



const express    = require('express'),
const app        = express();
const bodyParser = require('body-parser');


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


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

app.use(
    bodyParser.json()
);



let router = express.Router();


// http://localhost:8080/api

router.get('/', function(req, res) {
    res.json({ message: 'hooray! welcome to our api!' });   
});

router.get('/:id', function(req, res) {
    res.json({ message: 'hooray! welcome to our api id!' });   
});

app.use('/api', router);


app.listen(port);

console.log('Magic happens on port ' + port);


@xgqfrms
Copy link

xgqfrms commented Aug 29, 2020

module.exports & exports

Node.js

https://www.cnblogs.com/xgqfrms/p/13582032.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants