Getting Started with Node, Express and Postgres Using Sequelize

入门:学习用Express, Postgress 和Sequelize搭建简单的REST服务器

Getting Started with Node, Express and Postgres Using Sequelize

JavaScript Articles

$ mkdir -p postgres-express-react-node-tutorial/{bin,server}
$ cd postgres-express-react-node-tutorial
$ npm init -y

Install Express and a few of it's dependencies.

$ npm install --save express body-parser morgan

or

$ npm i -S express body-parser morgan
$ touch app.js

we'll need a way to restart the server every time we change something in our code. For that, we'll use the excellent nodemon npm package.

$ npm i -D nodemon

Now try running the application by executing

$ npm run start:dev

We are going to be making use of the Sequelize CLI package to bootstrap the project for us. It will also help us generate database migrations.

Let's begin by installing Sequelize CLI package.

$ npm install -g sequelize-cli

we are going to need to install the actual Sequelize package, alongside its dependencies.

$ npm install --save sequelize pg pg-hstore

With the paths defined, we will need to run the init command in order to create the specified folders and generate boilerplate code.

$ sequelize init

With the models and migrations in place, we're now ready to persist the models to the database by running the migrations.

$ sequelize db:migrate
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,461评论 0 10
  • 入门指南 1. 简介 Quickstart会让你启动和运行一个单节点单机HBase。 2. 快速启动 – 单点HB...
    和心数据阅读 4,769评论 1 41
  • 我像个神经病一样发愁,难过的想死掉。好希望二宝的眼睛没事,好希望睡一觉起来什么都变好了。 心痛死了,该如何是好。
    大脸宝宝宝阅读 131评论 2 0
  • 越在意什么就会被什么伤害,体会过的人才能懂吧! 这世界有太多的解释不了,有太多的别人体会不到! 三月底考完试,放假...
    北梧南木阅读 109评论 0 0
  • 幼儿挑食的原因是复杂的,要具体情况具体分析。有些幼儿的挑食可能是先天遗传因素造成的,而有些幼儿则可能是后天人为因素...
    Funmammy阅读 261评论 0 0